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

setOptions() new Field

5 Answers 382 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 11 Jul 2018, 11:06 AM

Hi,

I am saving the grid state in a database by calling grid.getOptions().
At opening the page, I am calling grid.setOptions(...) to restore the saved grid state. Its working well.

I added a new field to my grid, but it´s not visible, because in the stored grid state this field is not existing yet.

I can remove the array "columns" from the grid state JSON, but then the user settings of each column is deleted (for example the width of the columns).

 

What can I do to show the new field in my grid and not to delete the saved grid state?

 

Thanks,

Alex

5 Answers, 1 is accepted

Sort by
0
Accepted
Alex Hajigeorgieva
Telerik team
answered on 13 Jul 2018, 10:08 AM
Hello, Alexander,

When the Kendo UI Grid setOptions() is used, it first gets the current options and subsequently extends then with the provided object as a parameter to the setOptions() method.

To add another column to the existing columns set, you should parse the options object, and modify the options. columns array programmatically - either by appending or inserting the new column config. Using this approach will preserve the other columns settings and add the new one successfully:

// this example inserts the new column at index 0
var savedOptions = JSON.parse(options);                         
savedOptions.columns.splice(0,0,{field: "Address", width:150});
 grid.setOptions(savedOptions);
 
// this example pushes the new column at the end
var savedOptions = JSON.parse(options);                         
savedOptions.columns.push({field: "Address", width:150});
grid.setOptions(savedOptions);


Here is a runnable example which shows this approach in action:

https://dojo.telerik.com/@bubblemaster/oMaqAHUx

Let me know if need further help.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Alexander
Top achievements
Rank 1
answered on 13 Jul 2018, 10:28 AM

Hi Alex,

thanks for your reply and your example code. I modified your code for my needs and it worked well.

Best regards,

Alex

0
Alex Hajigeorgieva
Telerik team
answered on 13 Jul 2018, 12:16 PM
Hello, Alex,

Thank you for the positive feedback. Should you need further assistance, please feel free to get back to me.

Kind Regards,
Alex Hajigeorgieva
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Sai Chakradhar
Top achievements
Rank 1
answered on 11 Mar 2020, 08:10 AM

Hi @Alex,

I have a similar issue. 

I have saved my grid settings. And after that a column in the grid made editable. But when I am trying to use the old settings that column is not editable inline. Please help. 

Thanks. 

0
Alex Hajigeorgieva
Telerik team
answered on 13 Mar 2020, 08:07 AM

Hi, Sai,

There are two ways to solve this. Either set the column editable property to a function that returns false which will allow you to programmatically edit it:

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/configuration/columns.editable

Or, you can set the datasource.options.schema.model.fields.editable to false to make the property and respectively the column to which it is bound non-editable:

https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/configuration/schema#schemamodel

Regards,
Alex Hajigeorgieva
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Alexander
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Alexander
Top achievements
Rank 1
Sai Chakradhar
Top achievements
Rank 1
Share this question
or