Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
98
How to do remote paging on a dynamic result set?
posted

Hello,

    I need to do remote paging on a dynamic result set (both SQL & the selected columns are  dynamic), but the JSON returned from server side is:

 

{"Records":[{},{},{},{},{},{},{},{},{},{},{},
{},{},{},{},{},{},{},{},{}],
"TotalRecordsCount":41,"Metadata":{"timezoneOffset":28800000}}

 

Razor code:

@( Html.Infragistics().Grid<MVC3EntityFramework.Customer>()

        .AutoGenerateColumns(true)

        .Columns(column =>

        {

            column.For(x => x.CustomerID).DataType("string").HeaderText("Customer ID");

            column.For(x => x.CompanyName).DataType("string").HeaderText("Company Name");

            column.For(x => x.ContactTitle).DataType("string").HeaderText("Contact Title");

            column.For(x => x.ContactName).DataType("string").HeaderText("Contact Name");

            column.For(x => x.Country).DataType("string").HeaderText("Country");

        })

        .Features(features =>

        {

            features.Paging().PageSize(20).PrevPageLabelText("Previous").NextPageLabelText("NEXT");

            features.Sorting().Mode(SortingMode.Single).ColumnSettings(settings =>

            {

                settings.ColumnSetting().ColumnKey("AccountNumber").AllowSorting(true);

 

            });

            features.Selection().MouseDragSelect(true).MultipleSelection(true).Mode(SelectionMode.Row);

        })

        .DataSourceUrl(Url.Action("CustomerList"))            

        .Width("100%")

        .Height("350px")

        .DataBind()

        .Render()

)   

Controller method:

        [GridDataSourceAction]

        public ActionResult CustomerList()

        {

            return View(_dataContext.Database.SqlQuery<dynamic>("select * from customers").AsQueryable() );

        }

Parents
  • 23953
    Offline posted

    Hello yuanmai,

    Try using your model type "MVC3EntityFramework.Customer" as a type argument of System.Data.Entity.Database.SqlQuery method instead of "dynamic" keyword.
    For example your controller method should look like this:
      
    [GridDataSourceAction]
    public ActionResult CustomerList()
    {
     return View(_dataContext.Database.SqlQuery<MVC3EntityFramework.Customer>("select * from customers").AsQueryable() );
    }

    Hope this helps,
    Martin Pavlov
    Infragistics

     

Reply Children