Kendo UI One DataSource for Multiple Grid

匿名 (未验证) 提交于 2019-12-03 01:02:01

问题:

I have an issue with Kendo UI lately, I have 1 datasource and it is used by 3 grids. This is all working but for some reason styling of the grid is "dismantled" for a lack of better word.

If I filter the datasource from Grid A, Grid A looks good but Grid B and C would look something like this (don't mind the firstname "Error" in the column):

If I filter the datasource from Grid B, Grid B now will look good but Grid A and C will look "dismantled". What could be the problem?

Grid A:

    $('#grid-a').kendoGrid({       autoBind: false,       dataSource: emp_ds,       toolbar: kendo.template($("#mainlist-template").html()),       scrollable: true,       sortable: true,       selectable: 'row',       pageable: {         input: true,       },       columns: [{           field: "id",           title: "ID",           width: 100         },{           field: "firstname",           title: "Firstname"         },{           field: "lastname",           title: "Lastname"         }       ]     }); 

Grid B:

    $('#grid-b').kendoGrid({       autoBind: false,       dataSource: emp_ds,       toolbar: kendo.template($("#emplist-template").html()),       scrollable: true,       sortable: true,       selectable: 'row',       pageable: {         input: true,       },       columns: [{           field: "id",           title: "ID",           width: 100         },{           field: "firstname",           title: "Firstname"         },{           field: "lastname",           title: "Lastname"         },{            command: {             text: 'Select',             click: function(e) {               e.preventDefault();                if(employeeSelectSwitch == 2) {                 return;               }                varholder.curUid = $(e.currentTarget).closest("tr").data('uid');                $('#daterange-dialog').data('kendoWindow').center().open();             }           },           width: 140       }]     }); 

DataSource:

emp_ds = new kendo.data.DataSource({     transport: {       read: {         dataType: 'json',         url: url.employeeList       }     },     schema: {       model: {         fields: {           id: { type: 'number' },           firstname: { type: 'string' },           lastname: { type: 'string' },         }       }     },     pageSize: 15   }); 

回答1:

Jest thinking why you need 3 grids to display Same Data , Use 3 Datasource if you are not sharing the datasources. tale a look @ Kendo Shared Datasource .



回答2:

If you really want just one datasource that executes once, and you can't share it because each will be filtered differently,

You could populate the datasource in the background, and when the data comes back, split it amongst the grids like so:

 var dsBackground = new kendo.data.DataSource(myDsConfig);   dsBackground.read().then(function (e) {     if (dsBackground.data().length > 0) {         $(".parallel-grid").each(function() {             var grid = $(this).data("kendoGrid");             if (grid != null)             {                 dsBackground.filter({ field: "foo-type", operator: "eq", value:$(this).data("foo-type")});                 grid.dataSource.data(dsBackground.view());                 grid.dataSource.page(1);                 grid.dataSource.pageSize(10);             }         });     } }); 

Here is a working sample with some fake data:

http://dojo.telerik.com/@paltimus/EmUXE/2



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!