Forum
15:11
20/03/2009
For some unknown reason, when I try to loop on the selected rows on a multi select grid to delete it, the array containing the keys/rowid lose values thus not completing the whole deletion process.
For e.g:
var recs = $(”#mygrid”).getGridParam('selarrrow');
(recs variable in this example would hold [4,1] -> the row id's multiselected)
//alert(recs); ->should display 4,1
jQuery.each(recs,function(i,v){
alert(v);
$(”#mygrid”).delRowData(v);
});
The initial loop alert will display 4 and then remove the row with id 4. The next loop will display “undefined” in the alert box thus halting further row removal (with id = 1).
Inspecting grid.base.js, I have found that this line (306) is causing the problem
[line 306] if(ia != -1) {$t.p.selarrrow.splice(ia,1);}
The above line can't just be removed either as it will leave wrong values for getGridParam('selarrrow') after row removal (further deletion of records at the grid will not clear it's id's from selarrrow).
I hope the bug gets fixed soon. For now as temporary fix, I just issue a trigger “reloadGrid” to get a fresh updated grid data but with the expense of an extra query hit.
By the way, I'm using version 3.4.3
bonjo
11:00
Moderators
30/10/2007
Hello,
If you try this way:
for(var i=0;i<recs.length;i++){
$(”#mygrid”).delRowData(recs[i]);
}
What is happen?
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
04:02
hello tony, I used the code:
var recs = $(”#mygrid”).getGridParam('selarrrow');
for(var i=0;i<recs.length;i++){
$(”#mygrid”).delRowData(recs[i]);
}
The results are always just delete the selected count of records -1,why??thanks
ps:
var ids = new Array();
for(var i=0;i<ids.length;i++)
ids[i] = selids[i]; // copy the array to ids
for(var i=0;i<ids.length;i++){
$(”#mygrid”).delRowData(ids[i]);
}
The result is right, I don't know if this is a bug?
11:34
Moderators
30/10/2007
Hello,
This is very strange. In form editing we use the same code sniplet to delete a rows when we are in multiselect mode.
I'm not sure if this is connected with the delRowData, rather I think that there is a problem with the id's in the grid.
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
04:51
thanks,tony
add the test code in the loop ,please see:
var recs = $(”#mygrid”).getGridParam('selarrrow');
for(var i=0;i<recs.length;i++){
alert( recs.length); // test code
$(”#mygrid”).delRowData(recs[i]);
}
I found the array recs's length in per loop is Decreasing, it's leads to the wrong cause
Later ,open jquery.jqGrid.min.js,delete this code:
ia = $.inArray(rowid,$t.p.selarrrow);
if(ia != -1) {$t.p.selarrrow.splice(ia,1);}
save it ,retest it ,delete mulitselect record is right, I don't know that why use splice function in deRowData ??
10:49
Moderators
30/10/2007
Hello,
First of all thanks for this. Also I do not consider your problem deeper, so sorry for this.
The problem is not in delRowData.
Let consider what is happen:
1. You call getGridParam with selarrrow. The method direct return this array.
In other words recs is reference to selarrrow
2. You use this reference direct in the delRowData, but delRowData decreases the selarrrow (i.e the recs which is reference)
3. After every loop you have one elment little.
So to solve the problem I have modified the getGridParam
I will publish the fix soon. Need more testing.
Thanks again
Best regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
16:26
31/08/2012
onoank said:
Non of the solutions above work for me 🙁
Is there any solutions??
I had exactly the same problem and, as they explained above, the solution is to iterate the array downwards. This is a copy of my code that is working fine. You can include an alert in the middle of the loop to see how the rows are deleted starting from the tail.
var rowids = $('#list').jqGrid('getGridParam', 'selarrrow');
for (var i = rowids.length - 1; i >= 0; i--) {
$('#list').jqGrid('delRowData', rowids[i]);
}
I noticed the code above has a missing "-", check it out:
for(var i=len-1; i>=0; i–){
16:30
31/08/2012
nesken said:
onoank said:
Non of the solutions above work for me 🙁
Is there any solutions??
I had exactly the same problem and, as they explained above, the solution is to iterate the array downwards. This is a copy of my code that is working fine. You can include an alert in the middle of the loop to see how the rows are deleted starting from the tail.
var rowids = $('#list').jqGrid('getGridParam', 'selarrrow');
for (var i = rowids.length - 1; i >= 0; i--) {
$('#list').jqGrid('delRowData', rowids[i]);
}
I noticed the code above has a missing "-", check it out:
for(var i=len-1; i>=0; i–){
For some reason when I posted "i--" was change for "i-", you have to include two (2) dashes.
13:08
18/12/2012
I think I ran into this problem myself, the issue is that when the row is deleted by jqGrid it is (quite rightly) removed from the list of selected rows.
If when you loop over the rows to delete you are just looping over the list of selected rows then this array is changed on the fly by the delete function so it doesn't work quite as you might expect.
The workaround is to copy the array of selected rows using .slice() - or you could always try and delete the first entry in the array of selected rows.
Most Users Ever Online: 715
Currently Online:
74 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66