Author Topic: Dynamic colModel from database  (Read 1897 times)

rgorantla

  • Pro Deluxe
  • Jr. Member
  • *
  • Posts: 88
    • View Profile
Dynamic colModel from database
« on: August 23, 2017, 06:36:16 pm »
Instead of writing the colmodel - I am trying to make it dynamic i.e.e, to get the complete col-model from database.

ex: if there are new columns next year, i do not want to edit the JavaScript instead if i add a column in database with necessary properties - i should be able to get it with inline functions,etc...

Any way to do this?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Dynamic colModel from database
« Reply #1 on: August 24, 2017, 06:01:50 pm »
that's possible by using data structures in your server side language corresponding  to array of objects ( colModel ) and serializing it to JSON string similar to the way JSON string for data is created in the examples.

When page is loaded, convert JSON string to colModel array and add it to grid initialization object.

However note that inline functions can't be part of JSON string.

So inline functions have to be attached after loading colModel.

function cellRenderer(ui){
}
colModel[0].render = cellRenderer