Search code examples
slickgrid

Clear all rows from Slickgrid when closing modal window


I have 2 SlickGrids in a jquery modal layer.
I need to be able to clear all rows when modal layer is closed so that the grids are empty when/if the user reopens the modal layer later.
Actually I can do this with using:

dataViewMG1.beginUpdate();
dataViewMG1.getItems().length=0;
dataViewMG1.endUpdate();

but if I do this, I cannot repopulate the grids using any of my standard methods:

dataViewMG1.beginUpdate();
dataViewMG1.setItems(modaldata1);
dataViewMG1.endUpdate();
invmodalgrid1.invalidate();
invmodalgrid1.render();

Anyone have any ideas?? Thanks


Solution

  • I personally empty out my grid before refreshing the data, so it doesn't confuse the user thinking it's the actual refreshed data. That seems to be what you want to do here.

    My grid in HTML being:
    <div id="myGrid1" style="width:100%;height:680px;"></div>

    and in my JavaScript, I empty out the grid before refreshing it
    $('#myGrid1').empty(); // empty out the Grid before refreshing the data