Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
delRowData bug on Grid with Multiselect
20/03/2009
15:11
Avatar
bonjo
New Member
Members
Forum Posts: 1
Member Since:
20/03/2009
sp_UserOfflineSmall Offline

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

21/03/2009
11:00
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

24/12/2009
04:02
Avatar
lucy
Guest
Guests

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?

26/12/2009
11:34
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

30/12/2009
04:51
Avatar
luny
Guest
Guests

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 ??

30/12/2009
10:49
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

30/12/2009
17:05
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

Tony,

I dont think it /is/ a problem with getGridParam. Its a problem with how its being used. When I call getGridParam, I expect to get the actual grid parameter...

If the user wants a copy of the array, its easy enough to call $.makeArray on it.

Or for this case, just iterate downwards...

Mark

13/04/2010
23:12
Avatar
nate
New Member
Members
Forum Posts: 2
Member Since:
13/04/2010
sp_UserOfflineSmall Offline

Using $.makeArray to make a copy works, however this method is faster:

var recs = $("#mygrid").getGridParam('selarrrow');

var len = recs.length;

for(var i=len-1; i>=0; i–){

      $("#mygrid").delRowData(recs[i]);

}

Just traverse the array in reverse order.

~Nate

20/02/2012
16:06
Avatar
tempel
Member
Members
Forum Posts: 6
Member Since:
27/10/2011
sp_UserOfflineSmall Offline

not cool

07/08/2012
11:19
Avatar
onoank
New Member
Members
Forum Posts: 2
Member Since:
31/07/2012
sp_UserOfflineSmall Offline

Non of the solutions above work for me 🙁

Is there any solutions??

31/08/2012
16:26
Avatar
nesken
Panama
New Member
Members
Forum Posts: 2
Member Since:
31/08/2012
sp_UserOfflineSmall Offline

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–){

31/08/2012
16:30
Avatar
nesken
Panama
New Member
Members
Forum Posts: 2
Member Since:
31/08/2012
sp_UserOfflineSmall Offline

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.

18/12/2012
13:08
Avatar
meh-cfl
New Member
Members
Forum Posts: 1
Member Since:
18/12/2012
sp_UserOfflineSmall Offline

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.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
30 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information