jqGrid - Populating a treegrid with local data without using name:value format

StackOverflow https://stackoverflow.com/questions/16990447

  •  31-05-2022
  •  | 
  •  

Question

I am posting this for others who have a similar use case and looking for a solution. I welcome any feedback to my solution or if you have other ideas to solve the same use case.

Problem: I needed to populate a treegrid with local data. Here is the link to my use case.

The format of data required to populate a grid locally is:

var mydata = [{column1:value1, column2:value2}];

However, I wanted to avoid putting all the column names in "mydata". Instead, I wanted to use the data format as is the case when datatype is "json". Data format in such a case would be:

var mydata = {"rows": [{"id" :"1", "cell" :["value1", "value2"]}]};
Était-ce utile?

La solution

I solved the above use case in the following way:

1) Made the datatype: 'json'

2: Added a "beforeRequest" event to the treegrid (to prevent ajax request from firing)

 beforeRequest: function() {
        return false;
 }

3. Used addJSONData in the place where I wanted to add the data (Refer to the use case link)

jQuery("#tableId")[0].addJSONData(mydata);

I read some posts here suggesting to avoid addJSONData usage. However, I did not find any issues using addJSONData till now and would like to hear why addJSONData usage is bad.

I believe, there are other ways to solve the same problem (using localReader perhaps) and would love to know about them.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top