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

EnableCustomBinding and PageSize.

2 Answers 119 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.
Juan Pablo Perez
Top achievements
Rank 1
Juan Pablo Perez asked on 05 Oct 2010, 11:54 AM
Hello,

I've created a custom binding grid.

View:

	<%= Html.Telerik().Grid(Model.Models)
            .Name("Grid")
            .PrefixUrlParameters(false)
            .Columns(columns =>
                         {
                             columns.Bound(o => o.Code).Width(100);
                             columns.Bound(o => o.ISO3Code).Width(100);
                             columns.Bound(o => o.CDH).Width(100);
                             columns.Bound(o => o.Description).Width(400);
                             columns.Bound(o => o.DisabledDate).Width(100);
                         }
                    )
            .DataBinding(dataBinding => dataBinding.Ajax().Select("AjaxGrid""Countries"))
            .Pageable(settings => settings.PageSize(Model.PageSize).Total(Model.Total))
            .EnableCustomBinding(true)
            .Sortable()
            .Filterable()
%>


Controller:

        public ActionResult Index()
        {
            return View(new ViewModelCountries
                            {
                                Models = GetModels(new GridCommand()),
                                Total = _repository.Count,
                                PageSize = 5
                            }
                );
        }

        [GridAction(EnableCustomBinding = true)]
        public ActionResult AjaxGrid(GridCommand command)
        {
            return Json(new GridModel
                           {
                               Data = GetModels(command),
                               Total = _repository.Count
                           });
        }

Everything works properly except that PageSize. This is only working when Ajax binding is executed (show the 5 records I wanted), is that to say, it doesn't work (it shows the default 10 records) when the view is just loaded.

Any idea in how to resolve this?.

Thanks in advance.

Juan

2 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 06 Oct 2010, 08:43 AM
Hi Juan,

The cause for the behavior you are experiencing is due to the fact that when initially bound, the GridCommand's default PageSize value is used in your custom data retrial routine. Therefore, in order to correct this you should modify the GridCommand object, similar th the following:

public ActionResult Index()
{
    return View(new ViewModelCountries
    {
        Models = GetModels(new GridCommand() { PageSize = 5 }),
        Total = _repository.Count,
        PageSize = 5
    });
}


Regards,
Rosen
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
Juan Pablo Perez
Top achievements
Rank 1
answered on 06 Oct 2010, 11:36 AM
Rosen,

Now it works as I wanted.
Thank you very much for your answer.

Juan
Tags
Grid
Asked by
Juan Pablo Perez
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Juan Pablo Perez
Top achievements
Rank 1
Share this question
or