복붙노트

[JQUERY] 서버 측 페이징을 사용한 JQGRID 클라이언트 측 정렬 - 데이터가 사라집니다.

JQUERY

서버 측 페이징을 사용한 JQGRID 클라이언트 측 정렬 - 데이터가 사라집니다.

해결법


  1. 1.첫째, 로컬 정렬 및 서버 측 페이징을 사용하는 것이 좋습니다. 나는 사용자가 정렬 결과를 잘못 해석 할 수 있다는 것을 알게됩니다.

    첫째, 로컬 정렬 및 서버 측 페이징을 사용하는 것이 좋습니다. 나는 사용자가 정렬 결과를 잘못 해석 할 수 있다는 것을 알게됩니다.

    그럼에도 불구하고 고객이 로컬 정렬 및 서버 측 페이징을 조합 한 제한 사항에 동의하고 실제로 그것을 구현 해야하는 경우 다음 해결 방법을 제안 할 수 있습니다.

    onPaging: function() {
        $(this).setGridParam({datatype: 'json'}).triggerHandler("reloadGrid");
    },
    loadComplete: function (data) {
        var $this = $(this);
        if ($this.jqGrid('getGridParam', 'datatype') === 'json') {
            // because one use repeatitems: false option and uses no
            // jsonmap in the colModel the setting of data parameter
            // is very easy. We can set data parameter to data.rows:
            $this.jqGrid('setGridParam', {
                datatype: 'local',
                data: data.rows,
                pageServer: data.page,
                recordsServer: data.records,
                lastpageServer: data.total
            });
    
            // because we changed the value of the data parameter
            // we need update internal _index parameter:
            this.refreshIndex();
    
            if ($this.jqGrid('getGridParam', 'sortname') !== '') {
                // we need reload grid only if we use sortname parameter,
                // but the server return unsorted data
                $this.triggerHandler('reloadGrid');
            }
        } else {
            $this.jqGrid('setGridParam', {
                page: $this.jqGrid('getGridParam', 'pageServer'),
                records: $this.jqGrid('getGridParam', 'recordsServer'),
                lastpage: $this.jqGrid('getGridParam', 'lastpageServer')
            });
            this.updatepager(false, true);
        }
    }
    

    RecomeyTems를 사용하지 않으면 false JQGrid의 데이터 매개 변수를 채우는 코드가 조금 더 오래되지만 작동합니다.


  2. 2.위의 해결책은 우리가 그리드의 마지막 페이지에있는 경우 페이지가 5 행을 수용 할 수 있지만 마지막 페이지에 3 개의 행이 표시되는 경우를 제외하고는 잘 작동합니다. 이제 클라이언트 측 정렬을하려고하면 마지막 페이지가 2 개의 추가 행으로 채워지고 총 5 개의 행이 정렬됩니다. 나는 마지막으로 가져 오는 레코드가 버퍼에 저장되므로,이 일이 발생하는지 말할 수 있습니다. 이를위한 수정으로, onpagination, 그리드를 "json"으로 만들기 전에 그리드를 지우십시오. ClickOnPagination = function () { $ (이) .jqgrid ( "clearGridData"); $ (이) .setGridParam ({DataType : 'json'}). TriggerHandler ( "ReloadGrid"); } 소스 코드에서 $ t.p.records = 0; $ t.p.page = 1; $ t.p.lastpage = 0; 다음 페이지가 제대로 작동하도록 ClearGridData 함수에서.

    위의 해결책은 우리가 그리드의 마지막 페이지에있는 경우 페이지가 5 행을 수용 할 수 있지만 마지막 페이지에 3 개의 행이 표시되는 경우를 제외하고는 잘 작동합니다. 이제 클라이언트 측 정렬을하려고하면 마지막 페이지가 2 개의 추가 행으로 채워지고 총 5 개의 행이 정렬됩니다. 나는 마지막으로 가져 오는 레코드가 버퍼에 저장되므로,이 일이 발생하는지 말할 수 있습니다. 이를위한 수정으로, onpagination, 그리드를 "json"으로 만들기 전에 그리드를 지우십시오. ClickOnPagination = function () { $ (이) .jqgrid ( "clearGridData"); $ (이) .setGridParam ({DataType : 'json'}). TriggerHandler ( "ReloadGrid"); } 소스 코드에서 $ t.p.records = 0; $ t.p.page = 1; $ t.p.lastpage = 0; 다음 페이지가 제대로 작동하도록 ClearGridData 함수에서.

  3. from https://stackoverflow.com/questions/9030302/jqgrid-client-side-sorting-with-server-side-paging-data-disappears by cc-by-sa and MIT license