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
490
Remote Sorting
posted

I have remote binding and sorting set up and I can get data to populate but I am having trouble setting up my controller action correctly to handle the grid's sorting.

I set the DataSourceUrl in javascript because I don't want the grid to bind immediately on page load. $("#gridFind").igGrid('option', 'dataSource', '@Url.Action("GetData")');

What I am looking for is how to get sort information in the controller action. I know that I can go through Request.QueryString but that does not seem ideal. As I show in the action I can grab the page and pageSize using the model binder but the sort comes through different "sort(columnName)='desc'".

What is the preferred way to handle this? I have not seen a sample of how to do remote sorting in a controller action method.

Here is my grid and controller action

@(Html.Infragistics().Grid<ExistingData>()

    .ID("gridFind")

    .AutoGenerateColumns(false)

    .Columns(column =>

        {

            column.For(fr => fr.FltRecId).Hidden(true);

            column.For(fr => fr.DocNumCd).HeaderText("Document #");

            column.For(fr => fr.TofDateTimeDt).HeaderText("Takeoff");

            column.For(fr => fr.TrnorgNameNm).HeaderText("Organization");

            column.For(fr => fr.PlatformType).HeaderText("Platform");

            column.For(fr => fr.SideNumSn).HeaderText("Side Num");

            column.For(fr => fr.Crew).HeaderText("Crew");

        })

    .Features(features =>

        {

            features

                .Sorting()

                .Type(OpType.Remote)

                .Mode(SortingMode.Single)

                .ColumnSettings(settings =>

                    {

                        settings.ColumnSetting().ColumnKey("TofDateTimeDt").AllowSorting(true).CurrentSortDirection("desc").FirstSortDirection("desc");

                        settings.ColumnSetting().ColumnKey("DocNumCd").AllowSorting(true).CurrentSortDirection("asc").FirstSortDirection("desc");

                        settings.ColumnSetting().ColumnKey("TrnorgNameNm").AllowSorting(true).FirstSortDirection("asc");

                        settings.ColumnSetting().ColumnKey("PlatformType").AllowSorting(true).FirstSortDirection("asc");

                        settings.ColumnSetting().ColumnKey("SideNumSn").AllowSorting(true).FirstSortDirection("asc");

                        settings.ColumnSetting().ColumnKey("Crew").AllowSorting(false);

                    });

            features

                .Paging()

                .Type(OpType.Remote)

                .RecordCountKey("TotalRecordCount");

            features

                .Resizing();

        })

    .ResponseDataKey("ExistingData")

    .Render()

)

 

        [HttpGet]

        public JsonResult GetData(

            int page,

            int pageSize)

        {

            int iTotalCount;

            IList<ExistingData> data = m_repository.GetExistingData(out iTotalCount);

 

            JsonResult result = new JsonResult

            {

                Data =

                    new

                    {

                        ExistingData = data.AsQueryable(),

                        TotalRecordCount = iTotalCount

                    },

                JsonRequestBehavior = JsonRequestBehavior.AllowGet

            };

            return result;

        }

Parents
  • 24671
    Suggested Answer
    posted

    hi,

    you shouldn't do anything in order for this to work. you can refer to this sample:

    http://samples.infragistics.com/jquery/grid/remote-sorting

    basically you either need to mark your controller with the [GridDataSourceAction] attribute, or configure the grid in the controller and add the sorting feature. the grid logic parses the query string for sorting parameters, translates that to LINQ, etc. That's all done automatically for you.

    let me know if you have any specific issues with this scenario.

    Thanks,

    Angel 

Reply Children