Hi,
Can you please tell me how to achieve the following client side using javascript:
I have a radgrid with a GridClientSelectColumn.
When I select a grid row, I add the grid item to a MS Listbox.
Now, I want to be able to select the item in the Listbox, click a button that removes the item from the Listbox and also deselects the corresponding grid row.
I need it to do 2 things: 1.) Uncheck the GridClientSelectColumn checkbox, and 2.) remove the Highlighting (deselected state)
Thank you,
Andy
Can you please tell me how to achieve the following client side using javascript:
I have a radgrid with a GridClientSelectColumn.
When I select a grid row, I add the grid item to a MS Listbox.
Now, I want to be able to select the item in the Listbox, click a button that removes the item from the Listbox and also deselects the corresponding grid row.
I need it to do 2 things: 1.) Uncheck the GridClientSelectColumn checkbox, and 2.) remove the Highlighting (deselected state)
Thank you,
Andy
6 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 04 Dec 2009, 10:11 AM
Hello Andy,
You can try out the following code and see if it helps achieve the required:
js:
Thanks
Princy.
You can try out the following code and see if it helps achieve the required:
js:
| function Deselect() |
| { |
| var listbox = $find("<%=RadListBox1.ClientID %>"); |
| var listItem = listbox.get_selectedItem(); |
| var grid = $find("<%=RadGrid1.ClientID %>"); |
| var MasterTable = grid.get_masterTableView(); |
| var selectedRows = MasterTable.get_selectedItems(); |
| for(var i = 0; i < selectedRows.length; i++) |
| { |
| row = selectedRows[i]; |
| var cell = MasterTable.getCellByColumnUniqueName(row, "ColumnUniqueName") |
| if(cell.innerHTML == listItem.get_text()) |
| { |
| row.set_selected(false); |
| listbox.trackChanges(); |
| listbox.get_items().remove(listItem); |
| listbox.commitChanges(); |
| } |
| } |
| } |
Thanks
Princy.
0
Andrew
Top achievements
Rank 1
answered on 04 Dec 2009, 01:28 PM
Princy,
Thanks for your reply, but that didn't work at all.
row.set_selected(false); doesn't do anything in my case.
I'm not sure you understood my scenario.
Please follow these directions:
1. Create a grid with 2 columns. The first column is a GridClientSelectColumn (Checkbox). The second is a bound column.
2. Create a MS Listbox (not a Telerik Listbox).
3. Add a button below the Listbox, when clicked it should execute a Javascript Deselect function, based on the selected MS Listbox SelectedItem.
To test this, please click a checkbox for one of the Grid rows, which selects that row, and then adds the bound column item to the MS Listbox.
Now, select the item that was just added to the Listbox and click the Button (the Button Does NOT do a postback) that executes the Deselect function and should do 2 things:
1. Remove the item from the MS Listbox
2. Deselect the corresponding Grid row (along with unchecking the checkbox).
Thanks,
Andy
Thanks for your reply, but that didn't work at all.
row.set_selected(false); doesn't do anything in my case.
I'm not sure you understood my scenario.
Please follow these directions:
1. Create a grid with 2 columns. The first column is a GridClientSelectColumn (Checkbox). The second is a bound column.
2. Create a MS Listbox (not a Telerik Listbox).
3. Add a button below the Listbox, when clicked it should execute a Javascript Deselect function, based on the selected MS Listbox SelectedItem.
To test this, please click a checkbox for one of the Grid rows, which selects that row, and then adds the bound column item to the MS Listbox.
Now, select the item that was just added to the Listbox and click the Button (the Button Does NOT do a postback) that executes the Deselect function and should do 2 things:
1. Remove the item from the MS Listbox
2. Deselect the corresponding Grid row (along with unchecking the checkbox).
Thanks,
Andy
0
Princy
Top achievements
Rank 2
answered on 04 Dec 2009, 02:52 PM
Hi Andy,
You can replace the above code with the following and see if it helps:
js:
Hope this helps..
Princy.
You can replace the above code with the following and see if it helps:
js:
| function Deselect() |
| { |
| var listbox = document.getElementById("ListBox1"); |
| var listItem = listbox.value; |
| var grid = $find("<%=RadGrid1.ClientID %>"); |
| var MasterTable = grid.get_masterTableView(); |
| var selectedRows = MasterTable.get_selectedItems(); |
| for(var i = 0; i < selectedRows.length; i++) |
| { |
| row = selectedRows[i]; |
| var cell = MasterTable.getCellByColumnUniqueName(row, "Place") |
| if(cell.innerHTML == listItem) |
| { |
| row.set_selected(false); // Deselect the corresponding Grid row |
| for(var j = 0; j< listbox.children.length;j++) |
| { |
| if(listbox.children[j].innerHTML == listItem) |
| { |
| listbox.remove(j); //Remove the item from the MS Listbox |
| break; |
| } |
| } |
| } |
| } |
| } |
Hope this helps..
Princy.
0
Andrew
Top achievements
Rank 1
answered on 04 Dec 2009, 03:04 PM
Hi Princy,
No, that doesn't help. The problem is not with removing the item from the listbox. I can do that, it works fine.
The PROBLEM is with deselecting the grid row after removing the listbox item.
AS I SAID BEFORE,
row.set_selected(false);
as you provide in your code DOES NOT WORK. The row still remains selected.
Did you actually test the code you provided? If so, and it worked for you, then please provide me with the exact test code you used including the .aspx code and the javascript.
Thanks,
Andy
No, that doesn't help. The problem is not with removing the item from the listbox. I can do that, it works fine.
The PROBLEM is with deselecting the grid row after removing the listbox item.
AS I SAID BEFORE,
row.set_selected(false);
as you provide in your code DOES NOT WORK. The row still remains selected.
Did you actually test the code you provided? If so, and it worked for you, then please provide me with the exact test code you used including the .aspx code and the javascript.
Thanks,
Andy
0
Andrew
Top achievements
Rank 1
answered on 06 Dec 2009, 01:05 PM
Please answer my last post.
0
Hi Andrew,
Regards,
Yavor
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
If the information supplied thus far by the community, in this thread does not help, you can open a formal support ticket, and send us the problematic implementation, for further review. We will look into it locally, and get back to you with additional information.
Regards,
Yavor
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.