iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Hello,
I am using WebGrid Version 7 with latest hotfix. I have enabled AllowMultipleSelection="Yes" and have RestoreRowSelection = "All" and PersistRowChecker="False".
I want to find out a way by which I can clear the multiple selection of rows across pages, including the selected styling from the client side on click of a button say "Clear Selection".
Also, on the client side I am using the method "grid.RootTable.GetCheckedRows().length" to return me a count of the checked rows on the client side. But, this method does not return me a correct count. For e.g - When I select 4 rows in page 1, navigate to page 2 and select further 2 rows holding the ctrl key, then navigate back to page 1. Then instead of showing the count as 6 rows, it shows me count as 10 rows.
I guess it adds the selection in page 1 to its existing count, irrespective of me making any further selections to that page.
Thanks and appreciate your help.
Regarding the selected rows count, you could use the SelectedRows property in the multiple selection WebGrid. However, it will also exhibit the same issue as you described. A workaround will be to filter the unique key value of each selected row so we will only count the unique key value. Here is the snippet:
for(var i = 0; i < grid.RootTable.SelectedRows.length; i++){ var keyVal = grid.RootTable.SelectedRows[i].getAttribute('keyValue'); if(strKeyList.indexOf(keyVal + ";") < 0) strKeyList += grid.RootTable.SelectedRows[i].getAttribute('keyValue') + ";"}var strKeyArr = strKeyList.split(";");alert(strKeyArr.length - 1);
In order to clear selection in a WebGrid with classic paging, you will need to use the ClearSelection method and SelectedRows.Clear from WebGrid table Storage property. In your case, for multiple selection you will need to reselect one of the selected row before invoking ClearSelection so all the selected row will be cleared. Here is the snippet:
function ClearSelection(){ var grid = ISGetObject("wgTest"); var strKeyList = ""; for (var i = 0; i < grid.RootTable.SelectedRows.length; i++) { var keyVal = grid.RootTable.SelectedRows[i].getAttribute('keyValue'); if (strKeyList.indexOf(keyVal + ";") < 0) strKeyList += grid.RootTable.SelectedRows[i].getAttribute('keyValue') + ";" } var strKeyArr = strKeyList.split(";"); var rowKeyObj = new Array(); for (var j = 0; j < strKeyArr.length - 1; j++) { var currRowObj = grid.RootTable.GetRowByKeyValue(strKeyArr[j]); if (currRowObj) { rowKeyObj.push(currRowObj); } } if (rowKeyObj.length > 0) { rowKeyObj[0].Select(); grid.ClearSelection(); for (var k = 0; k < rowKeyObj.length; k++) { rowKeyObj[k].Uncheck(); } } grid.RootTable.Storage.SelectedRows.Clear();}
Hi,
Thank you for your reply.
I am trying the code to clear the row selection stated above. Can you please tell me in which client side event should I be adding this code. I tried to call the above function "ClearSelection()" during "OnAfterResponseProcess" event, which clears the selection, but it reappears after the page finishes loading. When I put an alert in the end of the "ClearSelection()" method, the selection is cleared, but as soon as the page finishes loading it appears back.
FYI: I am using "RestoreRowSelection = "ALL"
Thanks and appreciate your help
Regards
Dhaval.
Hi Dhaval,
I have tried my colleague snippet and it works just fine. Actually, you do not need to attach those ClearSelection() function into any client side event. From previous post, you have mentioned that you wanted "client side on click of a button say 'Clear Selection'". So, you can kindly try to use a regular HTML button that trigger this function. It should work nicely.
I hope it helps. Thank you and have a nice day.
Best Regards,
Andi Santoso
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname