I am using dhtmlxGrid library.
I am using the function updateFromXML to update the grid every few mins with fresh data ( on a timer ).
My problem is when I add mygrid.filterByAll(), the updateFromXML functionality breaks. It does not do inserts or deletes of the new rows. It just does the updates of existing rows. The doAfterUpdate function I have shown below has the broken code.
If I remove the line mygrid.filterbyAll everything works fine as expected.
Below is my code. I have shown a template of what I am doing .
<div id="gridbox" style="width:50%; height:500px; background-color:white;"></div>
<br>
<div><a href="#" onClick="start_timer_jobs()">Reload grid - Timer refresh data only </a></div>
<br>
<script>
var curr_sort = null;
var fetch_interval = null ;
function doAfterUpdate() {
mygrid.filterByAll(); ////something broken here.
if ( curr_sort.length > 0 ) {
console.log ( 'setting sorting' ) ;
var col_type = mygrid.getColType(curr_sort[0]);
mygrid.sortRows ( curr_sort[0] ) ;
}
return ;
}
function fetch_data ( ) {
curr_sort = mygrid.getSortingState();
var file_list = [ 'first.xml', 'second.xml', 'third.xml', 'first.xml', 'second.xml', 'third.xml' ]
var random_number = Math.floor((Math.random()*5));
var url = './test_dirs/' + file_list[ random_number ]
console.log ( 'fetch data ' + url ) ;
mygrid.updateFromXML(url, true, true , doAfterUpdate );
}
function start_timer_jobs ( ) {
console.log ( 'in timer' ) ;
if ( fetch_interval ) clearInterval(fetch_interval);
fetch_interval = setInterval(function() { fetch_data(); }, 10*1000);
}
mygrid = new dhtmlXGridObject('gridbox');
mygrid.setImagePath("./imgs/");
mygrid.setHeader("Sales,edtxt,ed,Price,In Store,Shipping,Bestseller,Publication");
mygrid.setColumnIds("Sales,edtxt,ed,Price,Store,Shipping,Bestseller,Publication");
mygrid.attachHeader("#numeric_filter,#text_filter,#numeric_filter,#numeric_filter,#numeric_filter,#numeric_filter,#numeric_filter,#text_filter");
mygrid.setInitWidths("50,150,100,80,80,80,80,200");
mygrid.setColAlign("right,left,left,right,center,left,center,center");
mygrid.setColTypes("ro,edtxt,ed,ro,ro,ro,ro,ro");
mygrid.setColSorting("int,str,str,int,str,str,str,str");
mygrid.init();
mygrid.enableColumnMove(true);
mygrid.enableSmartRendering(true);
mygrid.preventIECaching(true);
mygrid.setSkin("dhx_skyblue");
mygrid.loadXML("./test_dirs/grid.xml" );
</script>
I had a similar issue using filters on grids.
Pretty sure you need to:
If this does not work, then use clearAndLoad() instead: http://forum.dhtmlx.com/viewtopic.php?f=2&t=19603