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

[Solved] Delete a row programmatically

3 Answers 173 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
FinallyInSeattle
Top achievements
Rank 1
FinallyInSeattle asked on 29 May 2012, 09:19 PM
What is the proper way to delete a row programatically when using Batch editing mode (InCell)?

Thanks in advance!

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 31 May 2012, 11:54 AM
Hello Lori,

The Grid's deleteRow client-side method should be used to delete a row with code in InCell and in the other editing modes.

Regards,
Daniel
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
FinallyInSeattle
Top achievements
Rank 1
answered on 23 Jul 2012, 07:21 PM
Our delete code follows.  Upon hitting grid.deleteRow(row), I get the following error: "Object doesn't support property or method 'hasClass'".  In the minified telerik.all.min.js file, this is at 

    else{if(!o.hasClass("t-grid-new-row")){s=this.extractValues(o,true)}

When I examine "o", it has a value of "<tr class="t-master-row"> .... </tr>.
Can someone please assist?

Using version 2012.1.419.340.
//  We're handling the display of the Delete confirmation
function GridProducts_onDelete(e) {
    if (DeleteRow(e.row, true) == false) {
        e.preventDefault();
    }
}
 
function DeleteRow(row, promptForDelete) {
    var grid = $('#GridProducts').data('tGrid');
    if (!promptForDelete || confirm($("#DeleteLineItemNotification").val())) {
        rows = $(grid.element).find("tbody > tr.t-master-row:visible");
        grid.deleteRow(row);
 
        //  Check to see if we deleted the last row.  If so, re-add a blank one.
        if (rows.length == 1 && promptForDelete) {
            addNewItem(grid);
        }
 
        resetAddButtons(grid, "delete");
        updateProductCount(grid, true);
        renumberProducts(grid);
        return true;
    }
    else {
        return false;
    }
}
0
Daniel
Telerik team
answered on 24 Jul 2012, 11:20 AM
Hello Lori,

I posted my reply in the support ticket you have opened. For convenience, I am pasting it below:

The deleteRow method expects a row selected with jQuery and the event argument row property is a JavaScript row element. Modifying the code like in the snippet below should resolve the problem.

grid.deleteRow($(row));
Also, please note that the deleteRow method will trigger the OnDelete event and will cause a loop unless you use a flag that prevents any further calls. In order to avoid the loop, you could also add a custom command and execute the DeleteRow function when the button is clicked. 

Kind regards,
Daniel
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
Tags
Grid
Asked by
FinallyInSeattle
Top achievements
Rank 1
Answers by
Daniel
Telerik team
FinallyInSeattle
Top achievements
Rank 1
Share this question
or