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

[Solved] How do I make by grid page-able/sort-able.

7 Answers 150 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.
Ani Jalan
Top achievements
Rank 1
Ani Jalan asked on 21 Dec 2009, 07:55 PM

 I am new to MVC ( and web in general). I have, partial, view that lists a set of objects.

My main view gives users a bunch of options to filter their search (essentially forming a where clause) and I return the result to this partial view.

Partial Controller (FooListController):

        [GridAction]

        public ActionResult List(IEnumerable<Foo> dataSet)

        {

            return View(new GridModel< Foo > {Data = dataSet });

        }

 

View (List.aspx):

<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<GridModel<Foo>>" %>

        <%=

        Html.Telerik().Grid(Model.Data)

            .Name("FooList")

            .Columns(columns =>

                         {

                             columns.Add(o => o.Id);

                         })

           .Ajax(ajax => ajax.Action("List", "FooList", new {Model.Data}))

           .Sortable()

           .Pageable()

           .Filterable()

    %>

 

 

The problem is that when I page or sort my ‘List’ method is being called with null. I thought it would be my ‘Model.Data’. I don’t want to go back to my database for each paging ( my understanding was that ‘GridModel’ would magically take care of that, I could be wrong).

I can get into details of how I use the partial( its from one of the MSFT MVC blogs) but I don’t

 

believe its causing problems ( as it works for other parts).

7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 22 Dec 2009, 07:40 AM
Hi Ani Jalan,

Unfortunately I am not sure what you are trying to achieve. However I know that passing the whole model to the ajax method will not work.

If you want to configure your grid to do ajax paging and sorting you can check this online example. To implement filtering with text typed by the user - please check the project in this forum thread.

Let us know of you need further information.

Regards,
Atanas Korchev
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
Ani Jalan
Top achievements
Rank 1
answered on 29 Dec 2009, 06:18 PM

I have a form that allows user to specify several search criteria. Upon  posting the form I return a list of rows that match the filter( my filter becomes a SQL that I apply on a DB).

Now I want to page/sort on those rows only.

In the example you have the Controller always returns the complete set. For example in the related grids example

              [GridAction]

              public ActionResult _RelatedGrids_Orders(string customerID)

              {

                     customerID = customerID ?? "ALFKI";

 

                     return View(new GridModel<Order>

                     {

                           Data = GetOrdersForCustomer(customerID)

                     });

              }


You get the complete set of orders on each paging call.


I don’t want to do that because

  1. It’ll be hard for me to keep track of all 10 filter criteria ( aster the post)
  2. I can’t go to my database for each paging call and ask the same question.

 

I think I am missing something ( it shouldn’t be that hard or unique requirement).

0
Georgi Krustev
Telerik team
answered on 30 Dec 2009, 11:18 PM
Hello Ani,

In order to control more appropriate the returned data I will suggest you using custom data-binding for the second grid. Unfortunately there is no way how we can persist the filter data, because of the stateless nature of the ASP.NET MVC. In this case you should persist the filter criteria in a way, which suits you.

Let me know if I am missing something in your logic.

Best wishes,
Georgi Krustev
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
Missing User
answered on 01 Mar 2010, 04:42 PM
When using custom binding and an action like this

[GridAction]  
public ActionResult Index(GridCommand command)  
{  
    //action logic  
}  
 

can we stick our search criteria somewhere too? I'm thinking something like

[GridAction]  
public ActionResult Index(GridCommand command, MyCustomCriteria criteria)  
{  
    //action logic  
}  
 

so we wouldn't have to read the criteria from POST data but instead have them in a structured form (similar to what the default model binder does when having actions like public ActionResult Edit(Customer customer).
)
0
Atanas Korchev
Telerik team
answered on 01 Mar 2010, 04:46 PM
Hello Gabriel,

I think this is possible by using route values:

Grid()
      .Ajax(ajax => ajax.Action("Action", "Controller", new {searchCriteria = ""})

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
Missing User
answered on 01 Mar 2010, 05:55 PM
I tried doing a server binding, something like

.ServerBinding(settings => settings.Action("_BasicSearch""Product"new {basicSearchCriteria = new BasicProductSearchModel.BasicSearchCriteria(Model.Criteria.Query)})) 

as I discovered that the ajax binding is calling some ugly URLs that expose my object model details (namespaces, class names).
There is one good thing, and that is the correct action method is being called:

public ActionResult _BasicSearch(GridCommand command, BasicProductSearchModel.BasicSearchCriteria basicSearchCriteria) 

But there are two bad things:
1. the parameter in the action method is always null
2. after clicking the second page in the pager the form posts to this:
/product/_BasicSearch?basicSearchCriteria=<all my parent namespaces>.Models.BasicProductSearchModel%2BBasicSearchCriteria&Products-page=2 

just like the ajax binding did.

What I was expecting was the URL to remain the same and all the details (criteria, paging info, etc) to be sent via POST and prefferably without exposing my namespaces and class names. Am I asking for the impossible and I *do* need to instantiate my BasicProductSearchModel class in the beginning of the action method by looking in the POST variables?

Come to think of it, I remember reading that the grid paging only works via GET so I won't be finding my form inputs anywhere...

I'm still in the learning process so I may have too big expectations from MVC and telerik MVC.
0
Atanas Korchev
Telerik team
answered on 02 Mar 2010, 09:02 AM
Hi Gabriel,

When using server-side paging and sorting we are using GET requests. Indeed you won't be able to get the data from the post collection.

Using the ServerBinding(server => server.Action("action", "controller", routeValues) is the same as using Html.ActionLink - if you pass a complex object it will be serialized with full type etc. What you can do is pass the relevant properties of your object as route values. Then you can retrieve them in the action method and use them.

I hope this helps,
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.
Tags
Grid
Asked by
Ani Jalan
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ani Jalan
Top achievements
Rank 1
Georgi Krustev
Telerik team
Missing User
Share this question
or