Kendo UI Nuggets

Grid doesn’t like spaces in dataSource field names

(I happen to be subscribing to KnockoutJS observable here to receive data feed but that naturally depends on your framework of choice.)
Typical Kendo JS error: invalid template
Particularly note the way the columns property is generated.
[crayon toolbar=”always” lang=”js”]
sigCapVm.packingSlips.subscribe(function (newval) {
var gridPackingSlips = $(“#gridPackingSlips”);
var kgrid =“kendoGrid”);
if (kgrid && kgrid.columns.length);
else {
if (kgrid) kgrid.destroy();
//workaround for autogenerating columns with spaces
columns: $.map(Object.keys(newval.length === 0 ? {} : newval[0]),
function (el) {
if (el.startsWith(““)) return; //by convention, don’t show fields starting with “
return { field: ‘[“‘ + el.replace(“#”, “\#”) + ‘”]’, title: el }
}), //hash aka pound (#) is special character in kendo template syntax
dataSource: { data: newval },
noRecords: { template: “no records found for those inputs” },
height: “20em”,
change: function (e) {
//good to remember that we’re not doing a true knockout binding here vs setting the grid’s property above
//so we have to “manually” connect the selected row back to the viewmodel here
var selectedPackingSlip = e.sender.dataItem(;
var vm = ko.contextFor(gridPackingSlips[0]).$root;
resizable: true,
//scrollable: false,
sortable: true,
filterable: false,
selectable: true

Leave a Reply