When clicked, clear jqgrid and reload data

I have a jqgrid that is not inside document.ready. It will only work when a button is pressed.

function getData{ DataHandler.getTasks(locName,{callback:function(data){ jQuery("#TaskTable").jqGrid( { datatype : "local", data : resultSet, height : 250, width : 960, sortable : false, ignoreCase : true, sortorder : "desc", //rest of the table contents like colname and colmodel }); }, errorHandler:function(){ },async:false }); 

I would like to clear the grid every time I press a button to delete existing data and reload. Any help on this? Where should I provide a transparent grid inside the document or click a button?

thanks

+4
source share
2 answers

Assuming markup:

  <table id='myGrid' /> 

You can clear and download the latest data from the server using the following code:

 function loadTable() { $('#myGrid').jqGrid('GridUnload'); //this does the work of clearing out the table content and loading fresh data $('myGrid').jqGrid({ url: 'url goes here', dataType: 'json', jsonReader: { root: 'Data', page: 'CurrentPage', total: 'TotalPage', records: 'TotalRecords', repeatitems: false }, onSelectRow: editRow }); 

}

You can also check the following link for more information.

+7
source

So, this can be done as part of the button click event handler

Reset saved parameters from last message to jqGrid

 var postData = grid.jqGrid('getGridParam', 'postData'); $.extend(postData, { filters: "" }); 

Reset search fields that filter results

  $('#gbox_SearchResults').find('[id^="gs"]').val(''); 

Start reboot

 grid.jqGrid().trigger('reloadGrid', [{ page: 1}]); 
+2
source

All Articles