English 中文(简体)
Jqgrid - 触发 JqGrid 重新装入后, 多选择行不再持续
原标题:Jqgrid - Multiselectected rows no longer persist after triggering a JqGrid reload

我有一个多选择的 Jqgrid 。 最初, 我从服务器上用 Json 调用器装入网格, 当我从一页到另一页时, 多选择的行会保持正确 。

所选行的代号存储在数组中,而此数组则在调用时更新。我使用此数组来检查返回页面时已经选中的行。排序工作顺利,到目前为止我没有遇到任何问题。

在对特定字段应用过滤器时,请求被发送到服务器, 服务器将返回新过滤的结果为 Json, 然后重新装入网格 。

第一个页面被正确转换为选中行, 但是在修改页面和返回行时, 不再选择行。 但是, 数组仍然包含 ID, 并包含新添加的 ID 。

多重选择特性在重新装入后怎么停止工作? 还是因为重新装入而停止工作?

这是代码:

        <script type= text/javascript >
var selectedFieldsMap={};
var selectedFieldsObjs = [];
var selectedFieldIds = [];
$(function() {
    //function called when applying a filter
    $( #ApplyFilterBtn ).click(function() {
            saveGridState();
        $( #Grid ).setGridParam({ url: getUrl() });
        $( #Grid ).trigger( reloadGrid );
    });
});

function saveGridState() {
       var selectedIds = $( #Grid ).getGridParam( selarrrow );
       $( #Grid ).data(current_page, selectedIds);
       _.each(selectedIds, function(id) {
                selectedFieldIds.push(id);
            });
       var idsToBeAdded = _.difference(selectedIds, getExistingRowIdsForGrid( #list ));
       selectedFieldsMap[current_page] = idsToBeAdded;
       _.each(idsToBeAdded, function(id) {
       selectedFieldsObjs.push($( #Grid ).getRowData(id));
                   });
}

function getExistingRowIdsForGrid(gridSelector) {
var existingFields = $(gridSelector).getRowData();
return  _.map(existingFields, function(obj) { return obj.Id; });    

function resetFilterValuesAndReloadGrid() {
    //reset filters and set grid param
    $( #Grid ).setGridParam({
        sortname:  Id ,
        sortorder:  asc ,
        page: 1,
        url: getUrl()
    });
    $( #Grid ).jqGrid( sortGrid ,  Id , true);
    $("#Grid").trigger( reloadGrid );
}

    $("#Grid").jqGrid({
        url: getUrl(),
        datatype: "json",
        edit: false,
        add: false,
        del: false,
        height: 330,
        mtype:  GET ,
        colNames: [ Id ,  Type ,  Category ],
        jsonReader: {
            root: "DataRoot",
            page: "CurrentPage",
            total: "TotalPages",
            records: "TotalRecords",
            repeatitems: false,
            cell: "",
            id: "0"
        },
        colModel: [
            { name:  Id , index:  Id , width: 95, align:  center , sorttype: "int" },
            { name:  Type , index:  ValueTypeName , width: 110, align:  left ,sortable: true },
            { name:  Category , index:  Category , width: 72, align:  left , sortable: true },
        ],

        pager:  #pager ,
        rowNum: pageCount[0],
        rowList: pageCount,
        sortname:  Id ,
        sortorder:  asc ,
        viewrecords: true,
        gridview: true,
        multiselect: true,

        loadComplete: function () {
            if(selectedFieldIds) {   
         $.each(_.uniq(selectedFieldIds), function(index, value) {
                    $( #Grid ).setSelection(value, true);
                });
            }
        } ,

        onPaging : function () {
            saveGridState();
        },

        loadBeforeSend: function() {
            current_page = $(this).getGridParam( page ).toString();

        } ,
        onSortCol: function () {
            saveGridState();
        }
    });

}

function getUrl() {
//return url with the parameters and filtering
}
 </script>
最佳回答

问题解决了, 问题在于重新装入网格时, 检查行的函数被调用到文档中。 准备 () 和在网格加载时, 相同函数被调用 Compllete Compllete 。 切换发生, 选择被删除 。 我添加了一个条件来查看是否选中网格 。

 loadComplete: function () {
            var selRowIds = jQuery( #Grid ).jqGrid( getGridParam ,  selarrrow );
            if (selRowIds.length > 0) {
                return false;
            } else {
                var $this = $(this), i, count;
                for (i = 0, count = idsOfSelectedRows.length; i < count; i++) {
                    $this.jqGrid( setSelection , idsOfSelectedRows[i], false);
            }
            }
        }
问题回答

暂无回答




相关问题
Retrieving original row data from jqGrid

It is possible to use the getRowData method to retrieve the current of a cell but this retrieves the current cell content rather than the original data before it went through the formatter. How do I ...

How to programmatically select top row of JQGrid?

How does one programmatically select the top row of a JQGrid. I want to have the top row already selected when it is opened on the page. My grid is sorted by a descriptive column so the first row s id ...

Blank when NaN in jqGrid cells

How to set blank instead of NaN in jqGrid cells ? Using formatter ? Is there an example?

complete jqGrid?

Please, can anyone tell me how to use jqGrid? I want to do edit, add & delete functionality. Also I want to show an image in the grid Please tell me, what can I do, and how can I do?

jqGrid: is there an event for when columns are reordered?

I m using the column reordering feature in jqGrid $grid = jQuery("#list").jqGrid({ sortable:true, ... }); Is there an event that fires after columns are re-ordered? If there is, I can t see ...

Wrapping Text lines in JqGrid

Can you get lines of text to wrap in JqGrid? I have had a look round but i can t find anything.

using jqgrid style for usual Table in asp.net mvc

I d prefer using Table and td instead of JqGrid but i like JqGrid styles. has anyone used jqgrid style for usual Grid of asp.net MVC(i mean Table and td) before?

热门标签