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

[Solved] Is it possible to add route values to the Grid Cancel Command?

17 Answers 516 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.
Greg Hendee
Top achievements
Rank 1
Greg Hendee asked on 13 May 2010, 02:46 AM
Hello,

First off, this package has been great!  Thanks for the work on it, and for continuing to develop it. 

Currently, I have an issue with the grid, where I am using the Commands for Insert, Edit and Delete. When I use Insert or Delete, the new rows appear or go into edit mode, and everything is fine.  However, if the Cancel button is pressed, the route parameter has not been added to the Cancel Button action, so it fails.

Here is the Grid definition:

 

<% Html.Telerik().Grid(Model.tProducerSetup_Fees)  
                            .Name("FeeGrid")  
                            .ToolBar(commands => commands.Insert())  
                            .DataKeys(keys => keys.Add(c => c.SetupFeeID))  
                            .DataBinding(dataBinding => dataBinding  
                                .Server()  
                                      
                                    .Select("Edit", "ProducerSetup", new { id = Model.SetupID })  
                                    .Insert("InsertFee", "ProducerSetup", new { id = Model.SetupID })  
                                    .Update("UpdateFee", "ProducerSetup", new { id = Model.SetupID })  
                                    .Delete("DeleteFee", "ProducerSetup", new { id = Model.SetupID })  
                            )  
                            .Columns(columns => 
                                {  
                                    columns.Bound(c => c.FeeTypeID).Title("Fee Type").Width(100);  
                                    columns.Bound(c => c.CompanyID).Title("Payee").Width(200);  
                                    columns.Bound(c => c.FeeAmount).Title("Amount").Width(100).Format("{0}:C");  
                                    columns.Command(commands => 
                                    {  
                                        commands.Edit();  
                                        commands.Delete();  
                                    }).Width(200);  
                                })  
                           .Render();   
                              
                    %> 

and here is the controller method Edit, which a Cancel should return to (it does, just without the ID route value):

 

 

        public ActionResult Edit(int id)  
        {  
            SetHeader();  
            ViewData["EditTitle"] = "Edit Producer Setup";  
            ViewData["IsEditMode"] = true;  
 
            ProducerSetupRepository Setups = new ProducerSetupRepository();  
            ViewData["ProducerList"] = Setups.GetProducerList();  
            ViewData["AgencyList"] = Setups.GetAgencyList();  
            ViewData["ProgramList"] = Setups.GetProgramList();  
 
            tProducerSetup Setup = Setups.CurrentSetup(id);  
 
            ViewData["IsApproved"] = Setup.IsApproved;  
            ViewData["IsNew"] = false;  
 
            return View(Setup);  
        }  
 

Now, I have worked around this pretty easily with an overloaded Edit method, where I retrieve the ID and then call the correct method.  However, it would be nice to have the ability to route the Cancel button that is generated, or have it carry over the route values in their entirety from the original request.

Again, thanks a million for the work so far!  After this project is done, I will be adding some of the features to the source code to share with everyone.

17 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 13 May 2010, 09:39 AM
Hi Greg Hendee,

Which version are you using? I couldn't reproduce this with 2010.1.416. Normally the Cancel command is using the .Selec() setting so any route values should be taken from there.

All the best,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Andreas Maier
Top achievements
Rank 1
answered on 25 May 2010, 02:21 AM
I'm having the same problem. I use the grid to display details to a particular master record using server binding. On cancel I would like to go back to the unmodified details view for that particular record but the route information is lost. 
0
Atanas Korchev
Telerik team
answered on 25 May 2010, 07:00 AM
Hello Andreas Maier,

Which version are you using?

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Andreas Maier
Top achievements
Rank 1
answered on 26 May 2010, 04:40 PM
Telerik.Web.Mvc.dll is File/Product version 2010.1.309.235

If done some more investigation into this. I downloaded the source yesterday and have had a chance to investigate since. It looks more like a design issue to me at this point.  My situations is the following. I have a details view of a person on screen and I want to use the grid to display a list of associations with organizations that this person is related to.

So the grid is set up as follows (page model is the person object, list of associations is a collection):

URL is
/Person/Details/1

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PECC.Models.Persona>" %>

.....

           Html.Telerik().Grid( Model.PersonasOrgRols)
                .Name("rolegrid")
                .DataKeys( datakeys => datakeys.Add( dk => dk.ID))     //primay key on association table
                .Columns( c => {
                    c.Bound(o => o.ID);
                    c.Bound( o => o.OrganizaciónID);
                    c.Bound(o => o.RolID).Title("Role Name");
                    c.Command(s =>
                    {
                        s.Edit();
                        s.Delete();
                    });
                })
                .DataBinding(dataBinding =>
                            dataBinding.Server()
                                .Insert("InsertRole", "Person")
                                .Update("EditRole", "Person")
                                .Delete("DeleteRole", "Person")
                        )
                .Sortable()
                .Filterable(filtering => filtering.Filters(filters =>
                {
                    filters.Add(o => o.PersonaID).IsEqualTo(Model.ID); //not really needed in my context
                }))
                .Groupable()
                .Render();

Problem is that the primary key of the association table is not the only facotor in this context. I also need some reference to the primary key of the person table.

Looking into GridEditActionCommand.cs shows

 private void AppendCancelButton(Grid<T> grid, IHtmlNode parent)
        {
            var urlBuilder = new GridUrlBuilder<T>(grid);

            new HtmlTag("a")
                .Attributes(HtmlAttributes)
                .AddClass(UIPrimitives.Grid.Action, UIPrimitives.Button, UIPrimitives.DefaultState, UIPrimitives.Grid.Cancel)
                .Attribute("href", urlBuilder.Url(grid.Server.Select, routeValues =>
                {
                    grid.DataKeys.Each(dataKey =>
                    {
                        if (routeValues.ContainsKey(dataKey.RouteKey))
                        {
                            routeValues[dataKey.RouteKey] = string.Empty;
                        }
                    });
                    routeValues.Remove(grid.Prefix(GridUrlParameters.Mode));
                }) ) 
                .Text(grid.Localization.Cancel)
                .AppendTo(parent);
        }


This indicates that the datakeys are completely removed from the URL which in my example turns out to be /Person/Details
. But in my context this is not what I want. I want ot go back to /Person/Details/1 and show the list of associations for person 1.

Now this problem can be fixed (I added a property that appends to the cancel URL). But really the issue is with the design approach to datakeys. If in my scenario you try to edit the associations for a person the edit URL becomes /Person/Details/{number} the number being the primary ID of the associations table. However it should have the form /Person/Details/{ID person}/{ID association table}. I have hoped to resolve this by adding additional keys to the DataKeys property thus getting the right URL format (also setting the hidden id for each row in the appropriate way):
             
 .DataKeys(k => {
                    k.Add(o => o.PersonaID);
                    k.Add(o => o.ID);
                })

However when I use this approach for the datakeys ( your videos allude to this being acceptable) it seems like only the last added key gets preserved and used. I have not resolved why this is - all the code seems to be set up to be able to handle multiple keys.
 
So I'm stuck right now. Which is really a shame as I think the component is really fantastic.

Hope you can help me resolve this as it seems a common usage scenario.

Thanks,

Andreas
0
Atanas Korchev
Telerik team
answered on 26 May 2010, 04:53 PM
Hello Andreas Maier,

Upgrading to 2010.1.416 or newer should resolve this problem. If you don't have a commercial license you can download it from here.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Andreas Maier
Top achievements
Rank 1
answered on 26 May 2010, 05:17 PM
Getting a server error 500 for the link. I noticed the same error a little bit earlier when trying to go to search results.


0
Atanas Korchev
Telerik team
answered on 26 May 2010, 05:19 PM
Hi Andreas Maier,

I have updated the url.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Andreas Maier
Top achievements
Rank 1
answered on 26 May 2010, 05:55 PM
I'm not seeing any change in behavior with 2010.1.416.235. DataKeys still only seems to accept the last key added and the cancel behavior is as before.

To clarify - my goal it to have something like the demo


but with the capability to perform CRUD operations on the "Order" grid.
0
Atanas Korchev
Telerik team
answered on 27 May 2010, 06:33 AM
Hi Andreas Maier,

I couldn't reproduce the problem locally. Is it possible for you to send us a sample project? You need to either open a support ticket or host it somewhere as the forums do not allow attachments. Thanks!

Kind regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Andreas Maier
Top achievements
Rank 1
answered on 27 May 2010, 02:31 PM
Example project is at http://dl.dropbox.com/u/1419660/ExampleProject.zip . Please look at the person detail - listing two roles. The get request associated with the Edit/cancel buttons do not reflect the two datakeys added. Cancel basically is geared to get you back to an index page. Edit ignores the requirement of passing the ID for the person record.


0
Atanas Korchev
Telerik team
answered on 28 May 2010, 09:00 AM
Hi Andreas Maier,

Generally you can add route values to the Cancel by customizing the Select command:

.DataBinding(databinding => databinding.Server()
         .Select("Index", "Home", new {id = Model.ID}))


In your case however since the id is also a key in the grid it was incorrectly cleared from the route. I have fixed this problem. Find attached updated sample project. Use the dll and JavaScript files from the sample. Also I have modified the declaration of the datakeys:

.DataKeys(k =>
                {
                    k.Add(o => o.ID);
                    k.Add(p => p.PersonID).RouteKey("personID");
                })

This is required in order to add the second key as a different query string argument than "id" (which is the default).

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Andreas Maier
Top achievements
Rank 1
answered on 28 May 2010, 03:46 PM
This is fantastic. I just tested it and it works nicely now. This is a very common usage scenario for me. You may want to mention this capability in your documentation. I think it a very strong feature. Especially in combination template columns and whenever server binding is required.

Thanks for the quick turnaround on this.


0
Mohamed Mahmud
Top achievements
Rank 1
answered on 31 May 2010, 11:57 AM
hi all ..
i am sorry to report that the build you included has created another issue...
on my test project i have editor template for a property of type double .. and i am using ajax binding for inline editing.
the issue is :
when i am on the edit mode which gives me only that property and the rest of the row is readonly () .. when i click the update bottun to submit my value via AJAX ,, on the controller side i only get the grid parameters and the id .. the field i am supposed to update is not included.. when i downgrade from build 2010.1.528 to 2010.1.518 it works fine but the cancel issue returns.

thanks in advance ..
0
Atanas Korchev
Telerik team
answered on 31 May 2010, 12:03 PM
Hi Mohamed Mahmud,

I will need a sample project because the provided info is not sufficient in order to reproduce the problem.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mohamed Mahmud
Top achievements
Rank 1
answered on 31 May 2010, 12:51 PM
hi Atanas..
i have solved the problem .. i troubleshoot  the issue and i found that it was in the Scripts included in the 2010.1.528 version
so i copy the 2010.1.518 scripts and overwrite the 2010.1.528 scripts and it fixed the issue
0
Daniel
Top achievements
Rank 1
answered on 01 Apr 2011, 06:36 PM
I am having the same problem, but apparently I am needing a little help with the solution outlined above.  

When the grid is initially drawn, I take a look at the HTML and it has all the necessary ObjectId's are there to make edits, deletes, etc.  But if I click the edit button (inline editing), then just cancel (without making any changes), then I view the HTML once again, and all the identifying ObjectIds are gone so any future editing/deleting of that row fails.

Unlike Andreas, I only have one ID necessary to identify my row (BrokerId).  I tried adding ".RouteKey("BrokerId")" to the DataKey declaration, but that didn't seem to do anything.

Based on the Content subfolder, I was running version 2010.3.1318.  To try and help the problem, I installed version 2011.1.315... same problem.  What am I missing?  Please help!

@{Html.Telerik().Grid<myJ.Models.myjbroker>("brokers")
    .Name("BrokerGrid")
    .BindTo((IEnumerable<myJ.Models.myjbroker>)ViewData["brokers"])
    .DataKeys(keys =>
    {
        keys.Add(broker => broker.BrokerId).RouteKey("BrokerId");
     })    // How to uniquely identify this record
 
    .Editable(editing => editing.Mode(GridEditMode.InLine))
    .ToolBar(toolBar => toolBar.Template(@<text><a class="t-button t-button-icontext t-grid-add" href="/Journal/Brokers?mode=insert"><span class="t-add t-icon" style="margin-left:0"></span>Add Broker</a></text>))
 
    .Columns(columns =>
    {
        columns.Bound(broker => broker.Name).Width(175).ClientTemplate("<strong><#= Name #></strong>"); ;
        columns.Bound(broker => broker.AccountNumber).Width(100).Title("Account #");
        columns.Bound(broker => broker.Comments);
        columns.Command(commands =>
        {
            commands.Edit().ButtonType(GridButtonType.Image);
            commands.Delete().ButtonType(GridButtonType.Image);
        }).Width(80).Title("Actions");
    })
    .DataBinding(dataBinding => dataBinding.Ajax()
        .Select("_AjaxBrokerSelect", "Journal")   // Journal.Select to view the list
        .Insert("_AjaxBrokerInsert", "Journal")   // Journal.Insert inserts a new data record
        .Update("_AjaxBrokerUpdate", "Journal")   // Journal.Update updates an existing data record
        .Delete("_AjaxBrokerDelete", "Journal")   // Journal.Delete deletes an existing data record
    )
    .PrefixUrlParameters(false)
    .Resizable(resizing => resizing.Columns(true))
    .Pageable(paging => paging.PageSize(10).Style(GridPagerStyles.NextPreviousAndNumeric).Position(GridPagerPosition.Bottom))
    .Sortable(sorting => sorting.OrderBy(sortOrder => sortOrder.Add(b => b.Name).Ascending()))
    .Scrollable()
    .Render();
}
0
Marc
Top achievements
Rank 1
answered on 13 Dec 2011, 10:33 PM
Daniel, I can't say for sure, but likely your problem lies in the fact that you don't have BrokerID bound into a column. If you don't want it displaying, you can bind it and hide it with:

columns.Bound(broker => broker.BrokerID).Hidden();

The only other issue I could think of would be your Select action not repopulating the table correctly - Just keep in mind that clicking edit, insert, delete or cancel will run your Select action, so make sure every entry point into your select action is indeed passing the necessary attributes to repopulate.
Tags
Grid
Asked by
Greg Hendee
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Andreas Maier
Top achievements
Rank 1
Mohamed Mahmud
Top achievements
Rank 1
Daniel
Top achievements
Rank 1
Marc
Top achievements
Rank 1
Share this question
or