what can i do with my grid

2 posts, 0 answers
  1. zhang
    zhang avatar
    1 posts
    Member since:
    Jul 2017

    Posted 17 Jul 2017 Link to this post

    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: "湿度"
                        }]
                    });
                }
            }

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 19 Jul 2017 Link to this post

    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.
Back to Top