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

Delete row on client side

4 Answers 47 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.
Jerry
Top achievements
Rank 1
Jerry asked on 11 Jun 2012, 11:53 AM
Hi there,

I'm trying to delete a row on the client side.

following is my grid, I have a custom command that is used to trigger a javascript function, where I will get the key, then loop through data of the grid and try to remove that from the grid.


The problem is that I don't know how to pass the RecipientId to the javascript function. Could you give me an example?

@(Html.Telerik().Grid((IEnumerable<Alpaca.Website.FleetManagement.Models.RecipientModel>)ViewData["Recipient"])
                .Name("RecipientGrid")
                .DataKeys(keys => keys.Add(c => c.RecipientId))
                .Columns(col =>
                {
                    col.Bound(o => o.RecipientType).Width(100);
                    col.Bound(o => o.IsNotifySMS).Width(100);
                    col.Bound(o => o.IsNotifyEmail).Width(100);
                    col.Command(commands =>
                    {
                        commands.Custom("DeleteRecipient").Text("Delete").HtmlAttributes(new { onclick = "DeleteRecipient();return false;" });
                    }).Width(200);
                })
                .Sortable()
                .Groupable()
                .Filterable())

this is my javascript
function DeleteRecipient( eventArgs){
 
    alert(eventArgs);
}


regards
Jerry Ren

4 Answers, 1 is accepted

Sort by
0
Jerry
Top achievements
Rank 1
answered on 13 Jun 2012, 04:02 AM
can someone answer this post???

thank you
0
Petur Subev
Telerik team
answered on 13 Jun 2012, 01:33 PM
Hi Jerry,

Could you please share more information about your goal and give steps covering the exact workflow of the Delete button and why the built-in delete command is not appropriate in your case?
In the code snippet you are using Server binding and because of this the data field of the client Grid object wont contain any data (it is available only in Ajax binding). Also I would suggest you to use template column with a button inside instead of custom command (which is used to perform an request to the server).

Regards,
Petur Subev
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
Jerry
Top achievements
Rank 1
answered on 17 Jun 2012, 08:52 PM
Hi Petur,

sorry about late reply.

Well, basicaly, I don't want to make a call the controller when delete a row from the grid.

The built in delete command always make a call to the controller when deleting.

regards
Jerry
0
Petur Subev
Telerik team
answered on 19 Jun 2012, 09:52 AM
Hi again Jerry,

Each operation like Insert/Update or Delete performs a request to the server.
If you do not want to perform such request each time then you could use the Batch editing mode where all modified grid records are updated (saved, inserted or deleted) in a single batch (request to the server) when the "Save changes" button is clicked. 

Regards,
Petur Subev
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
Jerry
Top achievements
Rank 1
Answers by
Jerry
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or