free-jqgrid / jqGrid

jQuery grid plugin
https://github.com/free-jqgrid/jqGrid
Other
479 stars 195 forks source link

addRowData doesn't work for nested data #450

Open svattom opened 6 years ago

svattom commented 6 years ago

I am using free jqGrid 4.15.4. I have a grid using dot notation to reference nested fields in my row data, e.g. colModel: [{ name: "nested.name" }]

If the rows are added when the grid is constructed it works OK, but if I call addRowData to add rows later the nested values don't appear. This used to work pre-fork (4.7.0).

Here is a JSFiddle demonstrating the issue: https://jsfiddle.net/sj2gr7dh Here is a JSFiddle showing it working pre-fork: https://jsfiddle.net/2tjaegs4/

svattom commented 6 years ago

I managed to fix my specific issue locally. In parseDataToHtml where it populates rowData:

Old: rowData.push(addCell(idr, rd[cmName], j, i + rcnt, cells, rd)); New: rowData.push(addCell(idr, jgrid.getAccessor(rd, cmName), j, i + rcnt, cells, rd));

I noticed this commit where a similar issue was fixed. I also noticed a few other places where row data is fetched using direct array access instead of getAccessor.

OlegKi commented 6 years ago

Thanks for reporting the problem. I posted corresponding changes to GitHub. After that your demo start working: https://jsfiddle.net/OlegKi/sj2gr7dh/12/. The parseDataToHtml expect already parsed data, read before with respect of jgrid.getAccessor. Thus I made the fix inside of addRowData instead of modifying the code of parseDataToHtml. In any way thank you for reporting the problem.