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

[Solved] Ajax binding and paging : get PageSize and CurrentPageIndex

2 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.
Too
Top achievements
Rank 1
Too asked on 30 Nov 2012, 03:15 PM
Hello,

I'm trying to get from my data base only the data I need, not more.
I can have a lot of rows on my grid, so I don't want to get them all if not needed :
for example, if I have 5 pages of 10 lines, when I am on the first page, I just want to get the 5 first elements (#1 to 5) from my database. And if I go on the next page, I make an other querry to get the 5th following items (#6 to 10).

Here is what I have made, but I don't know how to pass the PageSize and the CurrentPageIndex of the grid to my controller. (I've put ??? in the following code)
...

@(Html.Telerik().Grid<
MyCDSModel>()
    .Name("Grid")
    .Columns(columns => {
                    ...
    })
    .DataBinding(dataBinding => dataBinding.Ajax().Select("AjaxBinding", "MyController", new { PageSize = ???, CurrentPageIndex = ??? }))
    .Scrollable(scrolling => scrolling.Enabled(false))
    .Sortable(sorting => sorting.Enabled(true))
    .Pageable(pager => pager.Enabled(true))
    .Pageable(pager => pager.Style(GridPagerStyles.Numeric | GridPagerStyles.NextPreviousAndDropDown))
    .Filterable(filtering => filtering.Enabled(true))
    .ClientEvents(events => events.OnLoad("onLoadGrid"))   
)

...

(And here is My Binding Class
/// <summary>
/// Ajax binding for the paging
/// </summary>
/// <returns>list of MyCDSModel</returns>
[GridAction]
public ActionResult AjaxBinding(int PageSize, int CurrentPageIndex)
{
  List<MyObjects> = MyDataBase.GetAll().Skip(PageSize * CurrentPageIndex).Take(PageSize);
  return ...
}
)

Thank you for your help

2 Answers, 1 is accepted

Sort by
0
Ivan
Top achievements
Rank 1
answered on 01 Feb 2013, 11:13 PM
Hello,

I am in the same position, have you found the solution?  If so, could you kindly post it here?

Thank you kindly,
    Ivan Pointer
0
David
Top achievements
Rank 1
answered on 09 Mar 2013, 02:20 AM
Me too. I need to get the telerik mvc grid's pagesize property and pass it to the controller since my controller needs this value. My controller action method is doing an Export to CSV and needs the pagesize value of the grid displayed in the view.

Anyone???
Tags
Grid
Asked by
Too
Top achievements
Rank 1
Answers by
Ivan
Top achievements
Rank 1
David
Top achievements
Rank 1
Share this question
or