This is a migrated thread and some comments may be shown as answers.

what can i do with my grid

1 Answer 84 Views
Grid
This is a migrated thread and some comments may be shown as answers.
zhang
Top achievements
Rank 1
zhang asked on 18 Jul 2017, 02:21 AM

i give the second datasource to the grid ,data has show , but the columns no change 

i do like this :

if (sjlx.value() == "t_ori_last") {
                $("#grid").kendoGrid({
                    dataSource: {
                        transport: {
                            read: {
                                type: "POST",
                                url: "../Handler/Handler_SJGL.ashx",
                                dataType: "json",
                                data: {
                                    Ptype: "apmreal",
                                    Pkeyword: $("#txt_keyword").val(),
                                    Pcounty: countyid,
                                    Psjlx: sjlx.value()
                                }
                            }
                        },
                        schema: {
                            model: {
                                fields: {
                                    STATIONCODE: { type: "string" },
                                    RECEIVETIME: { type: "string" },
                                    PM25: { type: "number" },
                                    PM10: { type: "number" },
                                    PM05N: { type: "number" },
                                    PM1N: { type: "number" },
                                    PM25N: { type: "number" },
                                    PM10N: { type: "number" },
                                    TEMPERATURE: { type: "number" },
                                    HUMIDITY: { type: "number" }
                                }
                            }
                        },
                        serverPaging: false,
                        batch: true,
                        pageSize: 25
                    },
                    height: ($(window).height() - 40),
                    sortable: true,
                    reorderable: true,
                    resizable: true,
                    filterable: true,
                    columnMenu: true,
                    //toolbar: [
                    //    {
                    //        name: "create",
                    //        text: "新增用户"
                    //    }
                    //],  
                    pageable: {
                        pageSizes: true,
                        buttonCount: 5,
                        input: true,
                        refresh: true,// 是否允许刷新页面 
                        numeric: false
                    },
                    change: function (e) {
                        $("#grid").data("kendoGrid").dataSource.read();
                        $("#grid").data("kendoGrid").refresh();
                    },
                    columns: [{
                        field: "STATIONCODE",
                        title: "编号",
                        width: 200
                    },
                    {
                        field: "RECEIVETIME",
                        title: "时间"
                    },
                    {
                        field: "PM25",
                        title: "PM25"
                    },
                    {
                        field: "PM10",
                        title: "PM10"
                    },
                    {
                        field: "PM05N",
                        title: "PM05数量"
                    },
                    {
                        field: "PM1N",
                        title: "PM1数量"
                    },
                    {
                        field: "PM25N",
                        title: "PM2.5数量"
                    },
                    {
                        field: "PM10N",
                        title: "PM10数量"
                    },
                    {
                        field: "TEMPERATURE",
                        title: "温度"
                    },
                    {
                        field: "HUMIDITY",
                        title: "湿度"
                    }]
                });
            }
            else {
                $("#grid").kendoGrid({
                    dataSource: {
                        transport: {
                            read: {
                                type: "POST",
                                url: "../Handler/Handler_SJGL.ashx",
                                dataType: "json",
                                data: {
                                    Ptype: "apmreal",
                                    Pkeyword: $("#txt_keyword").val(),
                                    Pcounty: countyid,
                                    Psjlx: sjlx.value()
                                }
                            }
                        },
                        schema: {
                            model: {
                                fields: {
                                    STATIONCODE: { type: "string" },
                                    RECEIVETIME: { type: "string" },
                                    PM25: { type: "number" },
                                    PM10: { type: "number" },
                                    TEMPERATURE: { type: "number" },
                                    HUMIDITY: { type: "number" }
                                }
                            }
                        },
                        serverPaging: false,
                        pageSize: 25
                    },
                    height: ($(window).height() - 40),
                    sortable: true,
                    reorderable: true,
                    resizable: true,
                    filterable: true,
                    columnMenu: true,
                    pageable: {
                        pageSizes: true,
                        buttonCount: 5,
                        input: true,
                        refresh: true,// 是否允许刷新页面 
                        numeric: false
                    },
                    columns: [{
                        field: "STATIONCODE",
                        title: "编号",
                        width: 200
                    },
                    {
                        field: "RECEIVETIME",
                        title: "时间"
                    },
                    {
                        field: "PM25",
                        title: "PM25"
                    },
                    {
                        field: "PM10",
                        title: "PM10"
                    },
                    {
                        field: "TEMPERATURE",
                        title: "温度"
                    },
                    {
                        field: "HUMIDITY",
                        title: "湿度"
                    }]
                });
            }
        }

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 19 Jul 2017, 08:10 AM
Hi Zhang,

If you need to change the columns structure dynamically you need to use the setOptions method of the Grid and re-initialize with the new configuration:
You should also have in mind that it is not supported scenario to initialize multiple Grids over the same element.


Best Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
zhang
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or