Ok now, how about extending jqGrid for tracking selection between pages. Here is a jquery extension that does the job.
; (function($) { $.jgrid.extend({ enableTracking : true, gridTrackingIds : null, TrackPageSelection: function (Rowids, selected, currentpageno) { var currentPage = this.GetCurrentPage(currentpageno); currentPage.RowIDs = new Array(); if(selected) { currentPage.RowIDs = Rowids; } this.UpdateSelection(currentPage); }, GetCurrentPage: function(currentpageno){ var selectedPages = $(this).jqGrid.gridTrackingIds; var currentGrid = this; if (selectedPages == null) { selectedPages = new Array(); } //find current page var currentPage = null; $.each(selectedPages, function (i, item) { if(item.Page == currentpageno){ currentPage = item; } }); if(currentPage == null) { currentPage = { Page : currentpageno, RowIDs : new Array() }; selectedPages.push(currentPage); } $(this).jqGrid.gridTrackingIds = selectedPages; return currentPage; }, UpdateSelection: function(currentPage){ var selectedPages = $(this).jqGrid.gridTrackingIds; var currentGrid = this; if (selectedPages == null) { selectedPages = new Array(); } var filteredPages = $.grep(selectedPages, function(elem, index) { return elem.Page != currentPage.Page; }); selectedPages = filteredPages; selectedPages.push(currentPage); $(this).jqGrid.gridTrackingIds = selectedPages; }, TrackSelection: function (id, selected, currentpageno) { var selectedItems = $(this).jqGrid.gridTrackingIds; //find current page var currentPage = this.GetCurrentPage(currentpageno); if(selected){ var itemIndex = $.inArray(id, currentPage.RowIDs); if(itemIndex == -1){ currentPage.RowIDs.push(id); } } else{ var filteredItems = $.grep(currentPage.RowIDs, function(elem, index) { return elem !== id; }); currentPage.RowIDs = filteredItems; } this.UpdateSelection(currentPage); }, UpdatePageSelection: function(currentpageno){ var selectedItems = $(this).jqGrid.gridTrackingIds; if(selectedPages != null) { //find current page var currentPage = this.GetCurrentPage(currentpageno); if(currentPage != null) { var selectedItems = currentPage.RowIDs; var currentGrid = this; if(selectedItems != null) { $.each(currentGrid.jqGrid("getDataIDs"), function (i, id) { if($.inArray(id, selectedItems) > -1) { currentGrid.setSelection(id, false); } }); } } } } ResetTracking: function(){ $(this).jqGrid.gridTrackingIds = null; } }); })(jQuery);
All you need is to just copy this into a .js file and add it to your project. Now on row select just call this
onSelectRow: function(rowid,selected) { var pageno = $(this).getGridParam('page'); $(this).TrackSelection(rowid,selected,pageno); }
At each increase of knowledge, as well as on the contrivance of every new tool, human labour becomes abridged.
Charles Babbage
0 comments:
Post a Comment