views:

56

answers:

1

I have a generalized php routine which generates xml results from different mySQL queries. The actual structure of the xml will vary depending on which query is used. (Actually, the number of columns will vary.)

I've just started to explore using jqGrid, and I'd like to write a generalized display routine where I do an ajax call to my php script to get the relevant xml, and then, based on the xml I get back, dynamically create the colModel for jqGrid (i.e. number of columns, column names, etc.).

Is this possible, and if so, how do I approach it?

+1  A: 

You could do this by making a separate AJAX request to retrieve the dynamic columns. Once you have that data, you would need to dynamically generate the colmodel and colnames options, and create the jqGrid using them. At this point, you could pass it a URL to retrieve data from, as long as the URL result set is guaranteed to contain all of the dynamic columns.

Does that help?

Justin Ethier
This is helpful and similar to another Stack Overflow response I found. See http://stackoverflow.com/questions/2277962/jqgrid-and-dynamic-column-binding. I was hoping not to have to do 2 queries to the data source, because it responds relatively slowly and overall performance will be negatively affected.
jalperin
Unfortunately you will need to make two requests, unless you can somehow do the dynamic column calculations on the server, before you render the initial page...
Justin Ethier