Kendogrid destroy() and recreate the table on a new datasource, why do the old table columns still exist?

霸气de小男生 提交于 2019-11-30 04:56:56

Most probably this is because you are not clearing the content inside the Grid container. e.g.

$('#gridName').data().kendoGrid.destroy();
$('#gridName').empty();

or shorter syntax

$('#gridName').kendoGrid('destroy').empty();

Other way the Grid takes into account the old html that is left - do not forget that the Grid could be initialized from table like here.

Just want to clarify on the last bit of Peter Subev's answer because it helped me:

"do not forget that the Grid could be initialized from table like here"

This is just saying that in your HTML you used a <table> tag rather than a <div> tag. Using a <table> tag separates the Grid table data from the Grid columns, so when you do $('#gridName').kendoGrid('destroy').empty() it is only destroying/emptying the table data and not the column information.

Switch your HTML <table> tag to a <div> tag to get the desired result.

I'm working in the angular framework and can't seem to reinit the Kendo grid with a new dataSource and new columns. Nothing works on the 2nd grid init. I've tried:

  if (vm.mainHierGrid != null) {
            //vm.mainHierGrid.data().kendoGrid.destroy();
            $('#mainGrid').data().kendoGrid.destroy();
            //$('#mainGrid').empty();
            vm.mainHierGrid.destroy();
        }

Destroy kendo grid and rebind it

if ($('#kgCopyEntityGrid').hasClass("k-grid")) {
                    $('#kgCopyEntityGrid').kendoGrid('destroy').empty();
                }

                var kgCopyGrid = $("#kgCopyEntityGrid").kendoGrid({
// your code here
                }).data("kendoGrid");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!