简体   繁体   中英

how can i get array data source, kendo-grid?

I'm getting array of properties and I want to show all of them in grid.

How to do it? Is it possible?

This is my code:

function StartBuild(ProfileProperties) {
        var details = [];
        for (i = 0; i < ProfileProperties.length; i++) {
            details[i]=[{ name: ProfileProperties[i][0], email: ProfileProperties[i][1], phoneWork: ProfileProperties[i][2], Mobile: ProfileProperties[i][3], ManagerName: ProfileProperties[i][4] }];
        }
             $(document).ready(function () {
            var datasource = new kendo.data.DataSource({
                transport: {
                    type:"odata",
                    read: function (e) {
                        e.success(details);
                    },
                    pageSize: 10,
                    batch: false,
                    schema: {
                        model: {
                            fields: {
                                name: { editable: false },
                                Fname: { editable: false }
                            }
                        }
                    }
                }
            });
            $("#grid").kendoGrid({
                dataSource: datasource,
                pegable: true,
                sortable: {
                    mode: "single",
                    allowUnsort: false
                },
                columns: [{
                    field: "name",
                    title: "name",
                    filterable: {
                        cell: {
                            enabled:true
                        }
                    }
                }, {//[Bild, nameP, email,phonework, Mobile, ManagerName]
                    field: "email",
                    title: "email"
                }, {
                    field: "phoneWork",
                    title: "phoneWork"
                }, {
                    field: "Mobile",
                    title: "Mobile"
                }, {
                    field: "Manager",
                    title: "Manager"
                }],
                filterable: {
                    mode: "row"
                },
            });
        });
    }

Only if I write details[0] it shows the first properties otherwise it doesn't show anything.

It looks like there are a couple of problems.

http://dojo.telerik.com/@Stephen/uVOjAk

First, the transport setup is incorrect. pageSize, batch, and schema are not part of the transport configuration...you need to take them out of the transport block and just have them in the datasource block.

You want:

var datasource = new kendo.data.DataSource({
    transport: {
        type:"odata",
        read: function (e) {
            e.success(details);
        }
    },
    pageSize: 10,
    batch: false,
    schema: {
        model: {
            fields: {
                name: { editable: false },
                Fname: { editable: false }
            }
       }
    }
});

Instead of(what you have):

var datasource = new kendo.data.DataSource({
    transport: {
        type:"odata",
        read: function (e) {
            e.success(details);
        },
        pageSize: 10,
        batch: false,
        schema: {
            model: {
                fields: {
                    name: { editable: false },
                    Fname: { editable: false }
                }
            }
        }
    }
});

Second, the details needs to be an array of objects, not an array of an array of an object.

You want:

var details = [];
for (i = 0; i < ProfileProperties.length; i++) {
    details.push({ name: ProfileProperties[i][0], email: ProfileProperties[i][1], phoneWork: ProfileProperties[i][2], Mobile: ProfileProperties[i][3], ManagerName: ProfileProperties[i][4] });
}

Instead of:

var details = [];
for (i = 0; i < ProfileProperties.length; i++) {
    details[i]=[{ name: ProfileProperties[i][0], email: ProfileProperties[i][1], phoneWork: ProfileProperties[i][2], Mobile: ProfileProperties[i][3], ManagerName: ProfileProperties[i][4] }];
}

Two other issues that are not directly causing a problem, but are incorrect are:

  1. Your dataSource.schema configuration does not match your actual data at all. The schema really needs to match the fields of the actual data otherwise it cannot match up the configuration.
  2. You spelled "pageable" wrong in the grid configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM