It doesn’t answer my question. Anyway, Thanks for your response.
Here is my code to handle alignment options on retrieval of the HandsonTable from any Database or anyother datasource:
Step-1: Create a method to handle the alignment options
/*
Method Description - Handles the alignment options for a single cell in the table.
*/
function handleAlignment(TD, row, column, prop, value, cellProperties) {
var _td = $(TD);
var css = {};
/* Extend the css object to set both Horizontal and Vertical alignment options */
if (cellProperties) {
/* Horizontal Alignment options. Set the style into the css object by extending it. */
var className = cellProperties['className'];
if (className != undefined && className != "" && className.indexOf('htCenter') != -1)
css = $.extend({}, css, { 'text-align': 'center' });
else if (className != undefined && className != "" && className.indexOf('htRight') != -1)
css = $.extend({}, css, { 'text-align': 'right' });
else if (className != undefined && className != "" && className.indexOf('htLeft') != -1)
css = $.extend({}, css, { 'text-align': 'left' });
else if (className != undefined && className != "" && className.indexOf('htJustify') != -1)
css = $.extend({}, css, { 'text-align': 'justify' });
/* Vertical Alignment options. Set the style into the css object by extending it. */
if (className != undefined && className != "" && className.indexOf('htMiddle') != -1)
css = $.extend({}, css, { 'vertical-align': 'middle' });
else if (className != undefined && className != "" && className.indexOf('htTop') != -1)
css = $.extend({}, css, { 'vertical-align': 'top' });
else if (className != undefined && className != "" && className.indexOf('htBottom') != -1)
css = $.extend({}, css, { 'vertical-align': 'bottom' });
/* Apply the css style with horizontal and vertical options to the respective cell in the table. */
_td.css(css);
}
}
Step-2: Add Handsontable event beforeRenderer
in the Handsontable initialization:
hot = new Handsontable(container, {
data: [[""]],
rowHeaders: false,
colHeaders: false,
filters: true,
renderAllRows: true,
dropdownMenu: true,
stretchH: 'all',
contextMenu: true,
mergeCells: true,
contextMenu: true,
/*
Before Column has been rendered, apply the properties of each cell as
Alignment or anyother cellproperties
*/
beforeRenderer: function (TD, row, column, prop, value, cellProperties) {
handleAlignment(TD, row, column, prop, value, cellProperties)
}
});
Here, beforeRenderer
is the main thing to work on.