开发者

jqgrid select rows by default based on column value

As an extension to my previous question, I would like to aut开发者_如何转开发omatically select rows by default. In this response, they use loadComplete to select rows after server request. However, I request from the server once and use local data from then on. I need instead to reselect rows every time the columns are organized, the grid is searched...basically every time the view of the data changes.

I select rows based on a column (book_id) rather than an explicit rowid, so would the answer here be appropriate? Or does jqGrid have an explicit method (onUpdateGrid, e.g.) to help achieve this goal? It looks for now that I would just have to replicate code under both onPaging and onSortCol.

The dataInit method for the fav_books column:

initBookEdit: function(elem){
  //populate reference table
  populateBookRefs($(elem).val());

  //display dialog which contains reference table
  //pressing OK button on dialog saves all id's as a
  //comma delimited list in the main table
  $('#bookRefPopup').dialog({
     buttons: {
    "OK": function(){
        var selectedRows = bookRefTable.jqGrid('getGridParam', 'selarrrow');
        var selectedIds = new Array();
        for(var i=0; i<selectedRows.length; i++){
            var changedRow = bookRefTable.getRowData(selectedRows[i]);
            var book_id = changedRow['book_id'];
            selectedIds.push(book_id);
        }
        var editedRow = $('#mainTable').jqGrid('getGridParam', 'selrow');
        $('#mainTable').jqGrid('setCell',editedRow, 'docs_ref', selectedIds, null, null, true);
        $('#mainTable').trigger('reloadGrid');
        $(this).dialog( "close" );
    },
    Cancel: function() {
        $( this ).dialog( "close" );
    }
}//close buttons
  });//close dialog
}

And the initialization of the reference table:

function populateBookRefs(ids){
  values = ids.split(',');
  grid.jqGrid({
     ...
     loadComplete:  function(){ //event executed after server request
        for(var i=0; i<values.length; i++){
          grid.jqGrid('setSelection',values[i],true);
        }

    }
     ...
  });
}


it looks like gridComplete will do what i want:

gridComplete: function(){   
    var grid_ids=grid.jqGrid('getDataIDs');
    for(var i=0; i<grid_ids.length; i++){
        var rowid = grid_ids[i];
        var aRow = grid.jqGrid('getRowData',rowid);
        var book_id = aRow['book_id'];
        if($.inArray(book_id,values)!=-1){
            grid.jqGrid('setSelection',rowid,true);
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜