tonytomov / jqGrid

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

Deleted row is displayed again. #932

Closed wonhyoung05 closed 4 years ago

wonhyoung05 commented 5 years ago

I found the issue that deleted row is show again. I attached the 'index_dnd_html.txt'. index_dnd_html.txt Full working demo here: delete_demo.zip

The test scenarios are:

  1. Move the row with id 11 from grid1 to grid2 ( drag and drop )
  2. Sort rows of grid1 by 'Id 1' ( click 'Id 1' )
  3. The moved row (id 11) is displayed at grid1 again.

It seems that the issue has occurred because $t.p.data did not updated in function delRowData.

Please refer to comments in the code.

js/jquery.jqGrid.js

        delRowData : function(rowid) {
                var success = false, rowInd, ia, nextRow;
                this.each(function() {
                        var $t = this;
                        rowInd = $($t).jqGrid('getGridRowById', rowid);
                        if(!rowInd) {return false;}

                                ... skip

                        if($t.p.datatype === 'local') {
                                var id = $.jgrid.stripPref($t.p.idPrefix, rowid),
                                pos = $t.p._index[id]; //  I guess that if 'datatype: "local" ' line in index_dnd.html  then $t.p._index has the wrong value. 
                                if(pos !== undefined) { //  This conditional statement is false.
                                        $t.p.data.splice(pos,1); // This line is not excuted. So $t.p.data is not updated.
                                        $t.refreshIndex();
                                }
                        }
                });
                return success;
        },
tonytomov commented 5 years ago

Hello,

Thank you for the test case.

The bug is not in delRowData.

The problem you have is in the grid settings.

You have at the same time

datatype:'local',
loadonce: true,
...

loadonce true does not have sense when the datatype is local, since local data is always present in data parameter.

loadonce have sense only if you load the data from the server and want to make it local.

To solve the problem remove loadonce:true from the both grid settings.

It seems to be a small problem in refreshIndex in case these parameters are set.

I will look at this.

Kind Regards, Tony

wonhyoung05 commented 5 years ago

Thank you for response.

After erasing 'loadonce: true', the issue is not occurs.

But there is another issue.

Scenario 1 works well. But Scenario 2 and Scenario 3 has issues. Please refer below.


Scenario 1 :

  1. Move the row with id 11 from grid1 to grid2. ( drag and drop ) The row id is "dnd_xxx". < tr id="dnd_xxx" ... >
  2. Move the row with id 11 from grid2 to grid1. ( drag and drop ) In delRowData(), "dnd_xxx" row's data is removed from $t.p.data.
  3. Sort rows of grid2 by 'ID 2' ( click 'Id 2' )

    Scenario 2 :

  4. Move the row with id 11 from grid1 to grid2. ( drag and drop ) The row id is "dnd_xxx". < tr id="dnd_xxx" ... >
  5. Sort rows of grid2 by 'ID 2'. ( click 'Id 2' ) The row id is changed. < tr id="11" >
  6. Move the row with id 11 from grid2 to grid1. ( drag and drop ) In delRowData(), "11" row's data is not removed from $t.p.data.
  7. Sort rows of grid2 by 'ID 2'. ( click 'Id 2' )
  8. The "11" row is displayed in grid 2 again.

Scenario 3 :

  1. Move the row with id 11 from grid1 to grid2. ( drag and drop ) The row id is "dnd_xxx". < tr id="dnd_xxx" ... >

  2. Move the row with id 23 from grid2 to grid1. ( drag and drop ) $("#jqGrid2")[0].p._index is changed. $("#jqGrid2")[0].p._index have "11", not "dnd_xxx"

  3. Move the row with id 11 from grid2 to grid1. ( drag and drop ) In delRowData(), "dnd_xxx" row's data is not removed from $t.p.data.

  4. Sort rows of grid2 by 'ID 2'. ( click 'Id 2' )

  5. The "11" row is displayed in grid 2 again.


At Scenario 2 step 2, While the addJSONData() function redraws rows, the row's id is changed. "dnd_xxx" => "11" But $("#jqGrid2")[0].p._index still have "dnd_xxx", not "11".

At Scenario 3 step 2, The still have same 'id' attribute value "dnd_xxx". But $("#jqGrid2")[0].p._index changed. $("#jqGrid2")[0].p._index have "11", not "dnd_xxx".

When deleting a row, if 's 'id' attribute value is not in $("#jqGrid2")[0].p._index, $("#jqGrid2")[0].p.data is not updated. ( Deleted row's data still remain in $("#jqGrid2")[0].p.data ) sortData() sort $("#jqGrid2")[0].p.data and display result. The data of the deleted row, remaining in $("#jqGrid2")[0].p.data, is displayed. Is it right?

tonytomov commented 5 years ago

Thanks for the investigation.

Currently you can omit this problem if you set autoid to false. The problem is that you have key true in colModel, but in the same way you force generation of id from the gridDnD.

To resolve do the following:

...
jQuery("#jqGrid1").jqGrid('gridDnD',{connectWith:'#jqGrid2', autoid : false}); 
jQuery("#jqGrid2").jqGrid('gridDnD',{connectWith:'#jqGrid1', autoid : false});
...