Deprecated: iconv_set_encoding(): Use of iconv.internal_encoding is deprecated in /home/datamerx/public_html2/codemerx/jqgrid/libraries/joomla/string/string.php on line 28

Deprecated: iconv_set_encoding(): Use of iconv.input_encoding is deprecated in /home/datamerx/public_html2/codemerx/jqgrid/libraries/joomla/string/string.php on line 29

Deprecated: iconv_set_encoding(): Use of iconv.output_encoding is deprecated in /home/datamerx/public_html2/codemerx/jqgrid/libraries/joomla/string/string.php on line 30

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/datamerx/public_html2/codemerx/jqgrid/libraries/joomla/filter/input.php on line 652

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/datamerx/public_html2/codemerx/jqgrid/libraries/joomla/filter/input.php on line 652
Remote Data - Local Filter/Sort/Select Part 2

Deprecated: Non-static method PhocaGalleryPath::getPath() should not be called statically, assuming $this from incompatible context in /home/datamerx/public_html2/codemerx/jqgrid/plugins/content/phocagallery/phocagallery.php on line 57

Deprecated: Non-static method PhocaGalleryPath::getInstance() should not be called statically, assuming $this from incompatible context in /home/datamerx/public_html2/codemerx/jqgrid/administrator/components/com_phocagallery/libraries/phocagallery/path/path.php on line 36

Deprecated: Non-static method PhocaGalleryLibrary::getLibrary() should not be called statically, assuming $this from incompatible context in /home/datamerx/public_html2/codemerx/jqgrid/plugins/content/phocagallery/phocagallery.php on line 64

Deprecated: Non-static method PhocaGalleryLibrary::getInstance() should not be called statically, assuming $this from incompatible context in /home/datamerx/public_html2/codemerx/jqgrid/administrator/components/com_phocagallery/libraries/phocagallery/library/library.php on line 44

Deprecated: Non-static method PhocaGalleryPath::getPath() should not be called statically, assuming $this from incompatible context in /home/datamerx/public_html2/codemerx/jqgrid/plugins/content/phocagalleryslideshow/phocagalleryslideshow.php on line 40

Deprecated: Non-static method PhocaGalleryPath::getInstance() should not be called statically, assuming $this from incompatible context in /home/datamerx/public_html2/codemerx/jqgrid/administrator/components/com_phocagallery/libraries/phocagallery/path/path.php on line 36

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/datamerx/public_html2/codemerx/jqgrid/libraries/joomla/filter/input.php on line 652

Remote Data - Local Filter/Sort/Select Part 2

  • Step 3 - Preserving the Sorting on Edit

So, when we do $(this).jqGrid('setGridParam', {datatype:'json'}).trigger('reloadGrid'); in step 2 all the data gets downoaded from the server again and jqGrid gets recreated. Naturally, any local sorting the user did will e gone at this point.

It is possile to save the sorting settings locally and re-sort jqGrid the same way after reload. A much better strategy, however, is tosort the data on the server side before sending it to jqGrid. Luckily, jqGrid sends the most sorting settings to the server using the sord and sidx URL parameters. The sidx (sort index) parameter is initialized to the column index (colModel index property) of the sorted column and sord (sort order) is initialied to either 'asc' ord 'desc' depending on the most recent sort order.

  • Step 4 - Preserving the Selected Row

If the user selected a row i jqGrid by clicking on it that selecion will get lost in two casesof our scenario:
- Local sort on a grid column
- Add/edit grid data, i.e. data reload

This demo shows how to deal with the first case. Rather unfortunately, it will not work in the second case. So, we need a different appoach.

Saving the selected row in jQuery cache should keep us on the safe side even when grid data gets reloaded. So let's explore this approach further.

These two functions save the selected row index in the jQuery cache of the grid <table> element.

var saveSelectedRow = function () 
{
$(this).data("selectedRow", $(this).jqGrid('getGridParam', 'selrow'));
};

var restoreSelection = function () 
{
$(this).jqGrid("setSelection", $(this).data('selectedRow');
};

These functions need to get called before the selection gets lost and after all the data is loaded. The demo  mentioned above defines pretty good hooks in case of local soting

$("#myGrid").jqGrid({
.....
onSortCol: saveSelection,
loadComplete: restoreSelection
.....
});

In case of adding/editing data we'll have to duse the grid tion properties as follows:

 

$("#myGrid").jqGrid('navGrid',"#myNavigation", {edit:true, add:true},
{
//On Edit
afterSubmit: function() { saveSelectedRow.call(this); return [true,,]; },
afterComplete: refresh,
},
{
//On Add
afterSubmit: function() { saveSelectedRow.call(this); return [true,,]; },
afterComplete: refresh,
});

var refresh = function() 
{
$(this).jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
restoreSelection.call(this);
};
   

Social Login  


 
   

Your Cart  


Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/datamerx/public_html2/codemerx/jqgrid/libraries/joomla/filter/input.php on line 652
The cart is empty
   

Latest Forum Posts  


Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/datamerx/public_html2/codemerx/jqgrid/libraries/joomla/filter/input.php on line 652

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/datamerx/public_html2/codemerx/jqgrid/libraries/joomla/filter/input.php on line 652

  • Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/datamerx/public_html2/codemerx/jqgrid/libraries/joomla/filter/input.php on line 652

  • Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/datamerx/public_html2/codemerx/jqgrid/libraries/joomla/filter/input.php on line 652