Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

on clicking a button, clear jqgrid and reload data

Tags:

jquery

jqgrid

I have a jqgrid which is not inside document.ready. It will be triggered only when I click a button.

  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 on every button click so as to remove the data already present and reload. Any help in doing this? Where should I give the clear grid inside document ready or on button click?

Thanks

like image 200
sahana Avatar asked Dec 26 '22 05:12

sahana


1 Answers

Assuming the markup of:

 <table id='myGrid' />

You can clear and load fresh data from the server by 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.

like image 124
KevinIsNowOnline Avatar answered Jan 15 '23 13:01

KevinIsNowOnline