0

When I try to expand a row of parent table to show a sub grid, the ID that is being passed is being generated by javascript. So the first row of the parent table gets a rowid of 1, second the rowid of 2. So when I click to expand the subgrid for each of them, the URL that gets called is myurl.html?q=1 and myurl.html?q=2. I'm using the q=? part of the query to fetch the rows for the subgrid.

However, the problem is that my parent rows are stored in the database with a unique id, which is not 1 2 3 etc. it is an autogenerated id by Mysql.

Question

How can I change the behavior of parentGrid or subGrid so that when subgrid is expanded, rather than autogenerated 1, 2, 3, etc. I get the actual ID of the parent row as it is in the DB.

birdy
  • 9,286
  • 24
  • 107
  • 171
  • You should be sending the actual id of the row in the data, can you show us sample of your data? – tpeczek Oct 22 '12 at 11:28

1 Answers1

1

You wrote about "autogenerated 1, 2, 3, etc". It shows that you fill the grid in not correct way. The data returned from the server should contain id used as the id of the rows (<tr>) and named frequently as rowid. Only if jqGrid don't find any information about rowids in the input data the values 1, 2, 3, etc will be used per default.

Such behavior is not only bad if you have native ids from the database the the rows of grid. More bad is that you could receive id duplicates if you have more as one grid on the page or if you have grid with subgrids.

So you should follow two rules:

  1. return the data which includes native ids from the database when the ids exist.
  2. use idPrefix if you use subgrids or if you have more as one grid on the page.

I recommend you to read the answer and this one. Another answer could be also interesting for you.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798