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

Grid within a PartialView

7 Answers 152 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.
Morne
Top achievements
Rank 1
Morne asked on 20 Nov 2009, 10:25 AM
We have a situation where we are using the Tab control and we need to have a grid in each one of the tabs. The grids get loaded onto the page on the LoadContentFrom() function on the tab strip.

We have placed the grid into a Partial View so that it can be re-used. Loading the populated grid onto the page works fine but the sorting and filtering only works on the grid in the first tab. Placing 4 grid declarations, 1 for each tab works perfectly, I think its because each grid now has a unique name.

I guess my question is... can you use a place a grid into a partial view and use it multiple times on a single page?


7 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 25 Nov 2009, 10:35 AM
Hello Morne,

You're on the right path - the unique name of the grid is the problem. You can resolve this by making the grid name a parameter of the partial view (i.e. through the view data for the partial view).

Sincerely yours,
Alex
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
P
Top achievements
Rank 1
answered on 22 Feb 2010, 02:05 PM
I have similar situation tabs + grids.
Everthing is loading as it should, but when i click on page/column header (to sort) or refresh button in grid, i am being redirected to this partial view (even that i'm using Ajax() databinding).

/Customers/Index -> sort click -> /Customers/partial_GridActive?GridActive-orderBy=LastName-asc
Any ideas?
Thank you in advance.
0
Alex Gyoshev
Telerik team
answered on 22 Feb 2010, 02:57 PM
Hi P,

Please make sure that the partial view renders the grids with different IDs (Names)

Kind regards,
Alex Gyoshev
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
P
Top achievements
Rank 1
answered on 22 Feb 2010, 04:00 PM
Grids have had different names.

I have fix it, but solution for it is really weird. I need additional grid on the main site.
I put it in not displayed div, and load to it empty data list. And now grids from tabs work well. (sic)

<div style="display: none">
        <%= Html.Telerik().Grid<CCommerceWeb.Models.Customer>(new List<CCommerceWeb.Models.Customer>())
            .Name("Grid")
                    .DataKeys(p => p.Add(o => o.Email))  // BTW SIC too, that key needs to be string to get commands working
                    .DataBinding(dataBinding =>
                             dataBinding.Ajax()
                                 .Select("_GetMockCustomers", "Client")                        
                         .Delete("_DeleteAjaxEditing", "Client")
                         .Update("_DeleteAjaxEditing", "Client")
                    )       
        .Columns(columns =>
        {
            columns.Bound(o => o.Id).Width(100);
            columns.Bound(o => o.LastName);
            columns.Command(p => p.Delete()).Width(100);
            columns.Command(p => p.Edit()).Width(100);
        })      
        
        %>
    </div>
--

0
Alex Gyoshev
Telerik team
answered on 22 Feb 2010, 04:41 PM
Hello P,

It seems that the grid JavaScript is not loaded initially - you could try to add its scripts manually in the ScriptRegistrar instead of adding the empty grid.

Best wishes,
Alex Gyoshev
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
Jeff Giesbrecht
Top achievements
Rank 1
answered on 29 Nov 2011, 06:09 PM
Alex,

Can you please show a code sample of how passing a name and making it a parameter of the partial view would work?

Thanks!
0
Alex Gyoshev
Telerik team
answered on 02 Dec 2011, 01:57 PM
Hello Jeff,

If you render the partial like this:

@{ var model = new string[] { "alpha", "beta", "ghamma" }; }

@Html.Partial("GridPartial", model, new ViewDataDictionary() { { "gridId", "someId" } })


you can use the ViewData in a partial like this:

@model string[]

@(Html.Telerik().Grid(Model)
    .Name((string)ViewData["gridId"]))

Regards,
Alex Gyoshev
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
Tags
Grid
Asked by
Morne
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
P
Top achievements
Rank 1
Jeff Giesbrecht
Top achievements
Rank 1
Share this question
or