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

[Solved] Server-side Row-based Action Links Inside a Template

1 Answer 85 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.
Merritt
Top achievements
Rank 1
Merritt asked on 11 Mar 2011, 09:34 PM
I often need to create my own custom commands for a given grid outside the scope of the built-in CRUD commands. For instance, I need to have a disable button for each row in a grid, and I am sort of stumped about how to maintain the grid state when doing so:

<% Html.Telerik().Grid(Model.Clients)
        .Name("Grid")
        .DataKeys(k => k.Add(o => o.Id))
        .PrefixUrlParameters(false)
        .Editable( e => e.Mode(GridEditMode.PopUp))
        .Sortable()
        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText))
        .DataBinding( b => b.Server()
            .Select("Index", "Client")
            .Update("Update", "Client")
            .Insert("Insert", "Client")
        )
        .Columns(columns =>
        {
            columns.Bound(o => o.Id).Visible(false).ReadOnly(true);
            columns.Bound(o => o.IP).Width(150);
            columns.Bound(o => o.TerminalNumber).Visible(true).Title("Terminal").Width(50);
            columns.Bound(o => o.Description).Width(300);
            columns.Bound(o => o.Disabled).Width(50);
            columns.Bound(o => o.Terminals).Visible(false).Sortable(false);
            columns.Template(c =>{
            %>
                <% using (Html.BeginForm("Disable", "Client", new { id = c.Id }, FormMethod.Post, new { @class = "t-grid-actions" }))
                { %>
                    <button class="t-grid-action t-button t-state-default" type="submit">Disable</button>
                <% } %>
            <% }).Width(50);
            columns.Command(s =>
            {
                s.Edit();
            }).Width(100);
        }).Render();
    %>

The problem with that template is it loses any order-by or sort-by information that I might have associated with the grid. I have noticed this information is accessible from the Edit command, and I see that it is appended in the query string  to the action links created (for Editing).

[HttpPost]
public ActionResult Update(EditableClientGridItem viewModel, GridCommand command, string mode, int? id)

The GridCommand command parameter contains all the information I need.





1 Answer, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 14 Mar 2011, 09:26 AM
Hi Merritt,

In order to achieve the requested functionality you should manually persist the grid's route values. I have attached a small sample which demonstrates how to implement such approach.

Regards,
Rosen
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Merritt
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or