Basic personalization
Table of contents
In this page you will learn how to:
- Apply custom classes to the table, headers and rows
- Apply even spacing
- Edit the grid appereance
As referenced before, please keep in mind that, for semplicity, all the examples use Tailwind as css framework. However, reTables does not restrict you in any way when choosing how to handle css.
Apply custom classes
You can start customizing your table from the basics by specifying css classes on the various elements.
Basic example
- BasicPersonalizationTable.tsx
- columns.ts
- Live example
function BasicPersonalizationTable() {
return (
<Table<Person>
indexKey='id'
data={people.slice(0, 3)}
columnConfigs={peopleColumns}
className='cursor-pointer' // Change the cursor when hovering on the table
baseHeaderClasses='font-bold bg-gray-100 dark:bg-stripe' // Assign background to the header
baseRowClasses='py-2' // Apply a base vertical padding
/>
);
}
export const peopleColumns: ColumnConfig<Person>[] = [
{ title: 'Id', key: 'id', flex: 0.5 },
{ title: 'Last name', key: 'about.lastName' },
{ title: 'Age', key: 'about.age', flex: 0.5 },
{ title: 'Job', key: 'about.job', flex: 1.5 },
{ title: 'Company', key: 'company', flex: 1.5 }
];
This is not the recomended way to apply padding and it's only for demostrating purposes. Visit this section to know more
Custom row style depending on row index
In the case of the row, there is also the possibility to specify different classes according to the index of the row. This is useful, for example, when you want to insert different colors on every other row to make reading easier.
- BasicPersonalizationTable.tsx
- columns.ts
- Live example
function BasicPersonalizationTable() {
return (
<Table<Person>
indexKey='id'
data={people.slice(0, 3)}
columnConfigs={peopleColumns}
className='cursor-pointer'
baseHeaderClasses='font-bold'
// Apply custom classes based on the row index
baseRowClasses={index => {
let baseClasses = 'py-2';
return index % 2 !== 0 ? baseClasses : `${baseClasses} bg-gray-100 dark:bg-stripe`;
}}
/>
);
}
export const peopleColumns: ColumnConfig<Person>[] = [
{ title: 'Id', key: 'id', flex: 0.5 },
{ title: 'Last name', key: 'about.lastName' },
{ title: 'Age', key: 'about.age', flex: 0.5 },
{ title: 'Job', key: 'about.job', flex: 1.5 },
{ title: 'Company', key: 'company', flex: 1.5 }
];
Note that you have also access to the isSelected
information. Please visit the Selection page of the documentation to know more about it.
Default cell spacing
Note that you have also access to the isSelected
information. Please visit the Selection page of the documentation to know more about it.
- BasicPersonalizationTable.tsx
- columns.ts
- Live example
function BasicPersonalizationTable() {
return (
<Table<Person>
indexKey='id'
data={people.slice(0, 6)}
columnConfigs={peopleColumns}
baseHeaderClasses='font-bold'
baseRowClasses={index => {
let baseClasses = 'cursor-pointer';
return index % 2 !== 0 ? baseClasses : `${baseClasses} bg-gray-100 dark:bg-stripe`;
}}
// Add custom cell padding
baseCellPadding={{
vertical: '10px',
horizontal: '10px'
}}
/>
);
}
export const peopleColumns: ColumnConfig<Person>[] = [
{ title: 'Id', key: 'id', flex: 0.5 },
{ title: 'Last name', key: 'about.lastName' },
{ title: 'Age', key: 'about.age', flex: 0.5 },
{ title: 'Job', key: 'about.job', flex: 1.5 },
{ title: 'Company', key: 'company', flex: 1.5 }
];
For more advanced use you can apply spacing yourself, using custom renderers.
Edit the grid appereance
The <Table />
component accepts a gridConfig
object with the following properties:
- BasicPersonalizationTable.tsx
- columns.ts
- Live example
function BasicPersonalizationTable() {
return (
<Table<Person>
indexKey='id'
data={people.slice(0, 6)}
columnConfigs={peopleColumns}
baseHeaderClasses='font-bold'
baseRowClasses={index => {
let baseClasses = 'text-sm cursor-pointer';
return index % 2 !== 0 ? baseClasses : `${baseClasses} bg-gray-100 dark:bg-stripe`;
}}
baseCellPadding={{
vertical: '10px',
horizontal: '10px'
}}
// Add custom grid config
gridConfig={{
showExternLines: EXTERN_LINE_GROUP.NONE,
showHorizontalLines: true,
showVerticalLines: false,
color: '#606770'
}}
/>
);
}
export const peopleColumns: ColumnConfig<Person>[] = [
{ title: 'Id', key: 'id', flex: 0.5 },
{ title: 'Last name', key: 'about.lastName' },
{ title: 'Age', key: 'about.age', flex: 0.5 },
{ title: 'Job', key: 'about.job', flex: 1.5 },
{ title: 'Company', key: 'company', flex: 1.5 }
];
Instead of specifying all the EXTERN_LINES
or none of them inside the showExternLines
, you can use EXTERN_LINE_GROUP.NONE
or EXTERN_LINE_GROUP.ALL
.