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
30
How to implement remote paging , filtering and sorting in iggrid in MVC
posted

Dear Team,

 

I am wanted to implement remote paging, filtering and sorting in one of my project which is in MVC 5. So far whatever I got from web is not enough to implement the same.

Below is my cshtml code. I am getting data from controller in json format.

       $('#Demo).igGrid({

        width: "100%",

        dataSource: data,

        responseDataKey: "Records",

        dataSourceType: "json",

        autoGenerateLayouts: false,

        autoGenerateColumns: false,

        columns: [

            { headerText: "No", key: "DeclarationNo",dataType: "number", template: "<a href='http://localhost:14152/Home/Sample/1'  > ${DeclarationNo} </a>" },

            { headerText: "Article No", key: "ArticleNo", template: "<a href='http://localhost:14152/Home/Sample/1'  > ${ArticleNo} </a>" },

            { headerText: "Article Name", key: "ArticleName",  template: "<a href='http://localhost:14152/Home/Sample/1'  > ${ArticleName} </a>" },

            { headerText: "Site Name", key: "SiteName", template: "<a href='http://localhost:14152/Home/Sample/1'  > ${SiteName} </a>" },

 

        ],

 

        features: [        

        {

            name: 'Paging',

            pageSize: 5,

            type: "remote",

            pageSizeDropDownLocation: "inpager",            

        },

        {

            name: 'Filtering',

            type: "remote",

            mode: "advanced",

            advancedModeEditorsVisible: true,

 

          

 

        },

                                {

                                    name: "ColumnMoving",

                                    addMovingDropdown: true,

                                    mode: "deferred",

                                    type: "render"

                                },

 

        {

            name: "Sorting",

            type: "remote",

 

           

        }

 

     

 

        ],

       

     

    });

 

2 – Below is my controller code

 

 

        [AcceptVerbs(HttpVerbs.Get)]

        public ActionResult GetAllDeclaration()

        {

 

            var listofDeclaration = GetPagedData();

            var model = listofDeclaration.Data.AsQueryable();

            return Json(model, JsonRequestBehavior.AllowGet);

        }

 

 

      

 

        public GridPagingInformation<Sample> GetPagedData(int pageSize = 10, int pageIndex = 0)

        {

            //var data = _sampleDataProvider.GetData(stateid);

            var data = _sampleDataProvider.GetData();

            var pagedData = data.Skip(pageIndex * pageSize).Take(pageSize).ToList();

 

 

 

            var listofstringfile = (data.Select(x => x.ArticleNo).ToList().Distinct());

            ViewBag.StringField = JsonConvert.SerializeObject(listofstringfile);

 

 

 

 

            var result = new GridPagingInformation<Sample>

            {

                Data = pagedData,

                PageNumber = pageIndex,

                PageSize = pageSize,

                TotalRecords = data.Count

            };

 

            return result;

        }