tonytomov / jqGrid

jQuery grid plugin
www.trirand.com
2.84k stars 1.2k forks source link

Problem (bug?) for Grid inside Cell #969

Closed unle70 closed 3 years ago

unle70 commented 4 years ago

Hello,

I'm trying to do something and I'm not sure if it's considered "legal" to do. I'm placing a grid inside a cell of another grid. It's a kind of sub-grid, but placed inline instead of the normal sub-grid which needs to be opened and appears in a separate row. I need to add that I plan to use editing (inline or cell, not decided yet) on the main grid and also on the "sub-grid".

While setting up my structure I have encountered a problem with the "getRowData" call: $grid.jqGrid('getRowData', rowid, false)

I kept getting an error in line 5250 ( nm = $t.p.colModel[i].name; ) saying the "name" was not found. After some more checking I have seen that the jquery select in the previous line (5249) is actually selecting the cells from BOTH the master grid and it's "sub-grid" (inside the cell). Looks to me that this is the root of the problem.

I tried to replace the select sentence and got good results. I'm not sure if my way of modifying the code might hurt some other functionality at another time.

Original: $('td[role="gridcell"]',ind).each( function(i) {

My proposal: $(ind).children('td[role="gridcell"]').each( function(i) {

This exact line appears second time in the jqgrid code, at line 13785 and needs to be modified the same way. After patching these 2 lines, I don't have any problem with the "getRowData" call anymore. I do however still see funny behavior of inline edit. When I invoke editing (click a cell) and then press escape to abort the editing, the cells of the inner grid (the "sub-grid") get cleared out (become blank), but not sure if this is jqgrid code fault or my own code fault.

So my questions are:

  1. Is it a valid option to place a grid inside a cell?
  2. Is this indeed an issue in jqgrid or am I missing something?

Thanks in advance, Udi

tonytomov commented 4 years ago

Thanks Udi. Both comments are ok. I will look into this at end of week.

Kind regards

tonytomov commented 3 years ago

Udi I have fixed your both problems:

  1. Using your proposal
  2. Restoring a only editable cells in inline edit.

Can you please confirm that the problem is fixed for you too?

Thank you

unle70 commented 3 years ago

Hi Tony,

Almost there. The first problem (getting an error) is fixed now. The second problem has improved, but not yet fully fixed. Still if I cancel the editing then some of the cells in the inner-grid get deleted. I have checked it and I believe the problem is in grid.base.js, line 5357. Looks like the same issue as the previous one, where the selector is not limited to the current level and also selects the inner levels.

The original line is: tcell = $("td[role='gridcell']:eq("+i+")",ind);

I have tried to change it to: tcell = $(ind).children("td[role='gridcell']:eq("+i+")");

Looks like it solved the problem. I did a quick search through jqGrid.js, trying to find ",ind". Looks like there are at least two more places where this same phrase is used, one in getCell and another one in editRow. I'm wondering if those should be modified as well.

What do you think?

tonytomov commented 3 years ago

Thanks Udi. I have fixed this line too. I do not think that the other two lines should be fixed (maybe)

Please let me know if the problem is fixed.

Kind Regards, Tony

unle70 commented 3 years ago

Hi Tony,

Yes, the problem I have seen has been solved.

Thanks, Udi