This is a migrated thread and some comments may be shown as answers.

Removing rows on "Del" key press

4 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Satish
Top achievements
Rank 1
Satish asked on 21 Sep 2012, 11:01 AM
Hi,
I need to remove the rows in radgrid on click of "Del" in keyboard. So I browsed the forum and got a solution to remove the radgrid rows from client side from this link
http://www.telerik.com/community/forums/aspnet-ajax/grid/delete-all-rows-in-a-radgrid-with-javascript.aspx#917286
So i got the below code

 

 

 

 

 

function keyPress(sender, eventArgs) {
        // Del button pressed
        if (eventArgs.get_keyCode() == 127) {
            var masterTable = sender.get_masterTableView();
            for (i = 0; i < masterTable.get_selectedItems().length; i++) {
                var it = masterTable.get_selectedItems()[i];
                var element = it.get_element();
                element.deleteRow(element.rowIndex);
            }
        }

After selecting the rows and Del key clicked in keyboard the event is called correctly. But the value of get_selectedItems() is incrementing without the newly selected list of items. Lets say first time if I select 1 row then the value of masterTable.get_selectedItems().length is 1 then Del click removed the row. Next time when i selected 2 rows and checked the value of masterTable.get_selectedItems().length, it is 3.
Why the selected items length is incrementing without being refreshed to 0.
Is my approach correct?

4 Answers, 1 is accepted

Sort by
0
Satish
Top achievements
Rank 1
answered on 21 Sep 2012, 02:58 PM
adding the following code at the end done the trick to clear the selected items so that only the recent selected list will be there all the time.

masterTable.clearSelectedItems(); 

any other thoughts?

0
Eyup
Telerik team
answered on 25 Sep 2012, 01:03 PM
Hello Satish,

Could you please try to use the following method?
masterTable.deleteSelectedItems();

That should do the trick. Please give it a try and let me know about the result.

All the best,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Satish
Top achievements
Rank 1
answered on 24 Oct 2012, 02:01 PM
Eyup,
I see that clearSelectedItems() works pretty good compared to deleteSelectedItems(). Any reason why you told me to try that?
0
Eyup
Telerik team
answered on 29 Oct 2012, 09:04 AM
Hi Satish,

I suggested you to try that since it is an internal supported method and the function will be quite shorter:
 
function keyPress(sender, eventArgs) {
   if (eventArgs.get_keyCode() == 127) {
       var masterTable = sender.get_masterTableView();
       masterTable.deleteSelectedItems();
   }
}

I hope this will prove helpful.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Satish
Top achievements
Rank 1
Answers by
Satish
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or