Skip to content

Column component

Configure your grid’s columns, using the props of the HotColumn component. Pass your component as a custom cell editor or a custom cell renderer.

Declare column settings

To declare column-specific settings, pass the settings as HotColumn props, the same way you do with HotTable.

Hooks, such as afterChange, run at the grid level only. Pass them to HotTable, not to HotColumn. Your IDE doesn’t suggest hooks as HotColumn props, and a hook you pass to HotColumn doesn’t run. For more information, see Events and hooks.

JavaScript
import { HotTable, HotColumn } from '@handsontable/react-wrapper';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
registerAllModules();
const hotData = [
['A1', 'B1'],
['A2', 'B2'],
['A3', 'B3'],
['A4', 'B4'],
['A5', 'B5'],
['A6', 'B6'],
['A7', 'B7'],
['A8', 'B8'],
['A9', 'B9'],
['A10', 'B10'],
];
const secondColumnSettings = {
title: 'Second column header',
readOnly: true,
};
const ExampleComponent = () => {
return (
<HotTable
// licenseKey="your-license-key" // get a key at https://handsontable.com/pricing/
data={hotData}
autoWrapRow={true}
autoWrapCol={true}
height="auto"
>
<HotColumn title="First column header" />
<HotColumn settings={secondColumnSettings} />
</HotTable>
);
};
export default ExampleComponent;
TypeScript
import { HotTable, HotColumn } from '@handsontable/react-wrapper';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
registerAllModules();
const hotData = [
['A1', 'B1'],
['A2', 'B2'],
['A3', 'B3'],
['A4', 'B4'],
['A5', 'B5'],
['A6', 'B6'],
['A7', 'B7'],
['A8', 'B8'],
['A9', 'B9'],
['A10', 'B10'],
];
const secondColumnSettings = {
title: 'Second column header',
readOnly: true,
};
const ExampleComponent = () => {
return (
<HotTable
// licenseKey="your-license-key" // get a key at https://handsontable.com/pricing/
data={hotData}
autoWrapRow={true}
autoWrapCol={true}
height="auto"
>
<HotColumn title="First column header" />
<HotColumn settings={secondColumnSettings} />
</HotTable>
);
};
export default ExampleComponent;

Object data source

When you use object data binding for <HotColumn/>, you need to provide precise information about the data structure for columns. To do so, refer to your object-based data property in HotColumn’s data prop, for example, <HotColumn data='id' />:

JavaScript
import { HotTable, HotColumn } from '@handsontable/react-wrapper';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
registerAllModules();
// a renderer component
const ScoreRenderer = (props) => {
const { value } = props;
const color = value > 60 ? '#2ECC40' : '#FF4136';
return <span style={{ color }}>{value}</span>;
};
// a renderer component
const PromotionRenderer = (props) => {
const { value } = props;
if (value) {
return <span>&#10004;</span>;
}
return <span>&#10007;</span>;
};
// you can set `data` to an array of objects
const data = [
{
id: 1,
name: 'Alex',
score: 10,
isPromoted: false,
},
{
id: 2,
name: 'Adam',
score: 55,
isPromoted: false,
},
{
id: 3,
name: 'Kate',
score: 61,
isPromoted: true,
},
{
id: 4,
name: 'Max',
score: 98,
isPromoted: true,
},
{
id: 5,
name: 'Lucy',
score: 59,
isPromoted: false,
},
];
const ExampleComponent = () => {
return (
<HotTable
// licenseKey="your-license-key" // get a key at https://handsontable.com/pricing/
data={data}
autoWrapRow={true}
autoWrapCol={true}
autoRowSize={false}
autoColumnSize={false}
height="auto"
>
{/* use the `data` prop to reference the column data */}
<HotColumn data="id" />
<HotColumn data="name" />
<HotColumn data="score" renderer={ScoreRenderer} />
<HotColumn data="isPromoted" renderer={PromotionRenderer} />
</HotTable>
);
};
export default ExampleComponent;
TypeScript
import { HotTable, HotColumn } from '@handsontable/react-wrapper';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
registerAllModules();
// a renderer component
const ScoreRenderer = (props: { value?: any }) => {
const { value } = props;
const color = value > 60 ? '#2ECC40' : '#FF4136';
return <span style={{ color }}>{value}</span>;
};
// a renderer component
const PromotionRenderer = (props: { value?: any }) => {
const { value } = props;
if (value) {
return <span>&#10004;</span>;
}
return <span>&#10007;</span>;
};
// you can set `data` to an array of objects
const data = [
{
id: 1,
name: 'Alex',
score: 10,
isPromoted: false,
},
{
id: 2,
name: 'Adam',
score: 55,
isPromoted: false,
},
{
id: 3,
name: 'Kate',
score: 61,
isPromoted: true,
},
{
id: 4,
name: 'Max',
score: 98,
isPromoted: true,
},
{
id: 5,
name: 'Lucy',
score: 59,
isPromoted: false,
},
];
const ExampleComponent = () => {
return (
<HotTable
// licenseKey="your-license-key" // get a key at https://handsontable.com/pricing/
data={data}
autoWrapRow={true}
autoWrapCol={true}
autoRowSize={false}
autoColumnSize={false}
height="auto"
>
{/* use the `data` prop to reference the column data */}
<HotColumn data="id" />
<HotColumn data="name" />
<HotColumn data="score" renderer={ScoreRenderer} />
<HotColumn data="isPromoted" renderer={PromotionRenderer} />
</HotTable>
);
};
export default ExampleComponent;