This is a migrated thread and some comments may be shown as answers.

Grid.SetOptions - Not working.

5 Answers 892 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nilesh
Top achievements
Rank 1
Nilesh asked on 31 Jul 2015, 06:55 AM

Hello,

I am wanting to persist the Grid settings (column re-ordering, sort order, etc), such that on subsequent page loads the grid settings are restored. The following JSBIN example http://jsbin.com/tonewefale/1/edit?js demonstrates my attempt to fetch and then restore the settings, however this does not seem to work as expected.

I am not sure, if I am missing on something obvious. Would be nice to have experts help me get a resolution to this problem.

Best Regards,
Nilesh Padbidri

5 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 04 Aug 2015, 06:49 AM
Hello Nilesh,

The issue that you are observing is due to the fact that once you call the setOptions method, the grid will take the data attributes with higher priority and will once again load the same values. As you could notice, if you remove the data-columns attribute, the columns order will be preserved with you current implementation. With that in mind, the only possible workaround for such requirement is to remove the data-columns attribute.
 

Best Regards,
Konstantin Dikov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Nilesh
Top achievements
Rank 1
answered on 04 Aug 2015, 02:34 PM

Hi Konstantin,

Thanks for the inputs.

Your suggested solution would seem to work only in such instances, when ALL properties in the Data Source should be visible in the grid. However, we have a situation where we want to be selective about which Data Source properties, should be displayed in the ​Grid & the programmatic approach to creating Grid and then calling SetOptions seems to work fine.

However as a thumb rule or coding standard in our project, we prefer the declarative approach over the programmatic approach. This leads me to ask you the question : Why when the declarative approach is used to create the grid, calling SetOptions should still trigger the attributes to have higher priority ? Can you please reason it out ?

It seems an awkward design decision to me, more on the lines of a anomaly rather than a design decision. Look forward to your response. Thanks once again.

Best Regards,
Nilesh Padbidri

0
Konstantin Dikov
Telerik team
answered on 05 Aug 2015, 10:11 AM
Hello Nilesh,

When you call the setOptions method, the widget will be recreated and its init method will apply the settings from the view model once again. If you need to change the columns according to the options that you are storing you could manually change the data-columns attribute just before you call the setOptions method, so it could match the new order.


Kind Regards,
Konstantin Dikov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Nilesh
Top achievements
Rank 1
answered on 05 Aug 2015, 10:31 AM

Hi Konstantin,

 

Thanks for your response. I am not sure, I understand what you mean, when you say change manually. Do you think, you could share a code sample to illustrate what you imply ?

 

Best Regards,
Nilesh Padbidri

0
Konstantin Dikov
Telerik team
answered on 07 Aug 2015, 06:23 AM
Hello Nilesh,

You will have to change the data-columns attribute and change the order of the columns in that attribute:
grid.element.attr("data-columns", newDataColumns);

The newDataColumns is a string value containing the columns definition with a new order. 

For your convenience, I have created an example with such implementation:
Once again, please keep in mind that setOptions is not designed to work with MVVM and that the above is just a workaround for the columns order.


Regards,
Konstantin Dikov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Nilesh
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Nilesh
Top achievements
Rank 1
Share this question
or