25
Bind igGrid with Json in the controller
posted

Hi,
I have a problem binding structure working with Json in controller to the I igGrid.
the data is missing in the grid. Have I do something wrong?

The Json result structure is:

{"rows":[{"id":0,"cell":[0,"type0"]},{"id":1,"cell":[1,"type1"]},{"id":2,"cell":[2,"type2"]},{"id":3,"cell":[3,"type3"]},{"id":4,"cell":[4,"type4"]},{"id":5,"cell":[5,"type5"]},{"id":6,"cell":[6,"type6"]},{"id":7,"cell":[7,"type7"]},{"id":8,"cell":[8,"type8"]},{"id":9,"cell":[9,"type9"]},{"id":10,"cell":[10,"type10"]},{"id":11,"cell":[11,"type11"]},{"id":12,"cell":[12,"type12"]},{"id":13,"cell":[13,"type13"]},{"id":14,"cell":[14,"type14"]},{"id":15,"cell":[15,"type15"]},{"id":16,"cell":[16,"type16"]},{"id":17,"cell":[17,"type17"]},{"id":18,"cell":[18,"type18"]},{"id":19,"cell":[19,"type19"]}]}

.chtml

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

        .ID("grid1")

        .Columns(column =>

        {

            column.For(x => x.Box_Number).DataType("int").HeaderText("Box_Number");

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

        })

        .Features(features =>

        {

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

            //Sorting

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

            {

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

 

            });

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

        })

        .AutoGenerateColumns(true)

        .PrimaryKey("Box_Number")

        .ClientDataSourceType(ClientDataSourceType.Function)

        .DataSourceUrl(Url.Action("GetAccountList"))

       

        .Width("100%")

        .Height("350")

        .LocalSchemaTransform(true)

        .DataBind()

        .Render() 

        )

 

 

HomeController.cs

 

public ActionResult GetAccountList()

        {

            var documents = _documentModule.GetDocumentsByGuids(new List<string>()).AsQueryable();

            var jsonData = new

            {

                rows = (

                           from m in documents

                           select new

                           {

                               id = m.Box_Number,

                               cell = new object[]

                                {

                                    m.Box_Number,

                                    m.Doc_Type

                                }

                           }).ToArray()

            };

            return Json(jsonData, JsonRequestBehavior.AllowGet);

        }