Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
Keep state of checkbox on IgGrid after sort

Hi all,

I have added checkbox input and sort feature on my igGrid, but after i click sort, all of my checkbox returns to original state. I think the reason is IgGrid re-render UI after sort and it makes our checkbox return to original state. 

I created a sample base on the template IgNiteUI supporter has given from another thread, please take a look and give me some advice for my problem and feel free to ask me if you don't understand what I ask, thank you!

Best regards,

Trung NT

No Data
  • 275
    Verified Answer
    Offline posted

    Hello Trung,

     I was able to look at the sample you have provided and the cause of this behavior seem to be the lack of updated values in the dataSource of the igGrid itself.

     It is exactly as you describe it. The igGrid re-renders the UI, but when re-rendering the cells it needs to read their values from somewhere. That place is the dataSource, that you have set initially . If these values are not updated, like in the sample remaining `true` even when unchecked, it will render the checkbox as their old values. Since the checkbox cells have a custom template, the igGrid is simply detached from anything that happen in these cells and won't know when the checkbox is checked to update the values in its dataSource.

     There are two ways to update the values. One way is to update the row in the "products" array directly and rebind the grid, which will update the dataSource with the new data . This though would be quite expensive when the data gets bigger. The other way is to enable Updating, disable its UI and manually set the new values for the cells through the igGrid, which will update the dataSource and will be faster.

     I have updated you sample with both possible scenarios so you can choose the one that suits you better. Hope they help and if you have any questions regarding them I would gladly answer them.