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

[Solved] Cannot get toolbar dynamic pagesize changer to work

0 Answers 91 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.
Phil
Top achievements
Rank 1
Phil asked on 03 Jun 2012, 05:31 PM
The following code that i have below is pretty simple.  I can confirm through brakepoints that the controller code and the javascript code are all getting hit, and sending the correct pagesize value to the viewdata.  But the pagesize of the actual grid never changes.  Any idea what I'm missing?  My grid is in a partial view if that matters, and the code in that partial view is:
<div>
    @{
        Html.Telerik().Grid<CoBRAMVCPortal.Models.ProjectModel>()
        .Name("prjgrid")
        .ToolBar(toolBar => toolBar.Template(
        @<text>
        <div style="text-align: right;vertical-align:middle;">
            <label class="editor-label">
                show pages with:
            </label>
            @(Html.Telerik().NumericTextBox().Name("numpgsize").MinValue(5).MaxValue(99).DecimalDigits(0).InputHtmlAttributes(new { style = "width:30px;" }).ClientEvents(events => events.OnChange("pagesizechange").OnLoad("onnumericload")).EmptyMessage(""))
            <label class="editor-label">
                items
            </label>
        </div>
        </text>))
        .Columns(columns =>
        {
            columns.Bound(o => o.ProjectDescription).Width(125);
            columns.Bound(o => o.FormattedDateCreated).Width(110);
            columns.Bound(o => o.FormattedDateOfLastEntry).Width(100).Title("Last Entry");
        })
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax().OperationMode(GridOperationMode.Client).Select("_GetProjectList", "Home", new { area = "" });
        }
                        )
                       .ClientEvents(clientEvents => clientEvents.OnDataBinding("dataBinding"))
               .Scrollable(scrolling => scrolling.Enabled(false))
               .Sortable(sorting => sorting.Enabled(true)).Pageable(paging => paging.Enabled(true).PageSize((int)ViewData["pagesizevd"]))
               .Filterable(filtering => filtering.Enabled(true)).Groupable(grouping => grouping.Enabled(false))
               .Footer(true).Render();
    }
</div>
<script type="text/javascript">
    function pagesizechange() {
        $("#prjgrid").data("tGrid").rebind();
    }
    function dataBinding(args) {
        var pagebox = $('#numpgsize').data('tTextBox');
        if (pagebox == undefined) {
            //args.preventDefault();
        }
        else {
            var pagesizeval = pagebox.value();
            args.data = $.extend(args.data, { pagesizeval: pagesizeval });
        }
    }
    function onnumericload() {
        var pagebox = $('#numpgsize').data('tTextBox');
        pagebox.value(10);
    }
</script>
and my controller data is:
public ActionResult Index()
{
    ViewData["pagesizevd"] = 10;
    return View();
}
 
[AcceptVerbs(HttpVerbs.Post)]
[Telerik.Web.Mvc.GridAction]
public PartialViewResult _GetProjectList(int? pagesizeval)
{
    ViewData["pagesizevd"] = pagesizeval ?? 10;
    IList<CoBRAMVCPortal.Models.ProjectModel> thePrjs = null;
    thePrjs = RefreshProjectList();
    return PartialView("ProjectList", new Telerik.Web.Mvc.GridModel(thePrjs));
}
Tags
Grid
Asked by
Phil
Top achievements
Rank 1
Share this question
or