I have the pleasure of dealing with the code someone else has written that affects every grid on our site (about 100).
Here is the problem. His default "DataBound" event resizes the action column we have at the left of our grids so that it matches the width of the displayed buttons. Makes sense. However, he has code in there that when the grid is intiialized, unbinds the current databound event then rebinds it to his special databound event. It looks like he assumed that this is the only usage we would ever have for databound.
I discovered this when i created a custom databound on a grid, and it was never called.
Is there a way to modify this code so that it stores the current databound event and reapplies it?
Here is the problem. His default "DataBound" event resizes the action column we have at the left of our grids so that it matches the width of the displayed buttons. Makes sense. However, he has code in there that when the grid is intiialized, unbinds the current databound event then rebinds it to his special databound event. It looks like he assumed that this is the only usage we would ever have for databound.
I discovered this when i created a custom databound on a grid, and it was never called.
Is there a way to modify this code so that it stores the current databound event and reapplies it?
gridSelector = gridSelector ||
"#grid"
;
// scoped function that can be assigned to the dataBoundEvent and called directly (below)
var
doGridDataBound =
function
(me, gridSelector, grid) {
me.InitMenu(gridSelector);
setTimeout(
function
() {
grid.autoFitColumn(actionColIndex);
}, 500);
};
var
grid = $(gridSelector).data(
"kendoGrid"
);
// delay "connecting" the dataBound event handler for 250ms to give time for other event handlers to be assigned first (we need this one to "fire" last)
// specifically - customKendoButtons_OnDataBound needs to fire earlier than this one to ensure that the buttons are visible/fully defined before "autoFit" is executed
grid.unbind(
"dataBound"
).bind(
"dataBound"
,
function
() {
doGridDataBound(me, gridSelector, grid);
});
/* if any data rows already exist, then the dataBound event will not fire again, so fire it now */
if
($(gridSelector).find(
"input.gridPopupHelper"
).length)
doGridDataBound(me, gridSelector, grid);