JqWidgets Grid: Maintaining filters after data is modified.

Invoke the updatebounddata method of the jqxGrid. Author: http://jqwidgets.com

by gombbc

HTML

<script src="http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/generatedata.js"></script>
<link rel="stylesheet" href="http://jqwidgets.com/public/jqwidgets/styles/jqx.base.css">
<link rel="stylesheet" href="http://jqwidgets.com/public/jqwidgets/styles/jqx.energyblue.css">
<script src="http://jqwidgets.com/public/jqwidgets/jqx-all.js"></script>
<div id='jqxWidget'>
    <div id="jqxgrid"></div>
</div>
    <div style="margin-top: 30px;">
        <input type="button" style="margin: 10px;" id="jqxbutton" value="Update bounded data" />
        <input type="button" style="margin: 10px;" id="jqxbutton2" value="Modify and rebind data" />
        <input type="button" id="saveState" value="Save State" />
        <input type="button" id="loadState" value="Load State" />
    </div>

JavaScript

var data = generatedata(500);
var filters;
  var state = null;
 var source = {
     localdata: data,
     datafields: [{
         name: 'firstname',
         type: 'string'
     }, {
         name: 'lastname',
         type: 'string'
     }, {
         name: 'productname',
         type: 'string'
     }, {
         name: 'date',
         type: 'date'
     }, {
         name: 'quantity',
         type: 'number'
     }, {
         name: 'price',
         type: 'number'
     }],
     datatype: "array"
 };

 var adapter = new $.jqx.dataAdapter(source);
 $("#jqxgrid").on('bindingcomplete', function () {
     
     //Loading the state will reset filters in a way
     //that is understandable to users (e.g. it will
     //remove items in the "checkedlist" filters which
     //are no longer valid options as well as maintaining
     //the valid options which were selected)
     //to make it work we need to load the state after
     //we have bound the data.
      if (state) {
          $("#jqxgrid").jqxGrid('loadstate', state);
      } else {
          $("#jqxgrid").jqxGrid('loadstate');
      }
 });
 $("#jqxgrid").jqxGrid({
     width: 500,
     theme: 'energyblue',
     source: adapter,
     sortable: true,
     selectionmode: 'checkbox',
     showfilterrow: true,
     filterable: true,
                     pageable: true,
                pagesize: 10,
                pagesizeoptions: [5, 10, 25, 50],
     columns: [{
         text: 'First Name',
         datafield: 'firstname',
         columngroup: 'Name',
         width: 90,
         filtertype: 'checkedlist'
     }, {
         text: 'Last Name',
         columngroup: 'Name',
         datafield: 'lastname',
         width: 90
     }, {
         text: 'Product',
         datafield: 'productname',
         width: 170,
         filtertype: 'checkedlist'
     }, {
         text: 'Order Date',
         datafield: 'date',
         width: 160,
         cellsformat: 'dd-MMMM-yyyy'
     }, {
         text: 'Quantity',
       ...