sidebarDepth |
---|
2 |
With all the customizable features of Frappe Charts, this section is dedicated to enabling / disabling existing functionality.
The first parameter required by the DataTable
constructor is the container element. You can pass in a CSS Selector or a DOM Object.
const datatable = new DataTable('#datatable', options);
// or
const container = document.querySelector('#datatable');
const datatable = new DataTable(container, options);
The second parameter required by the DataTable
constructor is the options object. The minimum required configuration is to pass column
and data
values.
const options = {
columns: ['Name', 'Position', 'Salary'],
data: [
['John Doe', 'DevOps Engineer', '$12300'],
['Mary Jane', 'UX Design', '$14000'],
]
}
const datatable = new DataTable(container, options);
The following options are configurable:
Function
null
Customize the editor behaviour.
Boolean
true
Whether to show serial number as the first column in datatable.
Boolean
false
Whether to show checkbox column in the datatable.
Boolean
true
Whether to use clusterize to render the data.
If you don’t want to show large number of rows. Then you can turn this off. In that case you don’t need to load the
clusterize.js
lib
String
fixed
fixed | fluid | ratio
This option controls how width of each column
is calculated in the DataTable.
The column width is calculated based on the content of the first row of the table. This layout can result in horizontal scroll.
The column width is adjusted based on the width of container. So the columns will be resized if the window is resized. This layout won’t result in horizontal scroll. You will always see all the columns.
This layout works similar to the flex
property in CSS. When column A has width
set as 1
and column B as 2
, then column B’s width will be twice as much as column A.
String
No Data
The message shown when there are no rows to show in the DataTable.
Boolean
false
The height of the row will be set according to the content of the cell with the maximum height in that row.
Number
null
Set the height of each cell explicitly.
If this value is set,
dynamicRowHeight
won’t have any effect.
Boolean
false
Whether to enable the inline filter feature. If the value is true
, then you can activate the filter row by pressing Ctrl/Cmd + F
after clicking on any cell in the DataTable.
Boolean
false
Whether to render rows in a tree structure. For this to work, you must pass the indent
value for each row.
Example
const data = [
{
'Department': 'IT Department',
'No of People': '10',
'indent': 0,
},
{
'Department': 'Javascript Team',
'No of People': '5',
'indent': 1,
},
{
'Department': 'Vue.js Team',
'No of People': '3',
'indent': 2,
},
{
'Department': 'React Team',
'No of People': '2',
'indent': 2,
},
{
'Department': 'Design Team',
'No of People': '5',
'indent': 1,
},
]
const datatable = new DataTable('#datatable', {
columns: ['Department', 'No of People'],
data: data
});
Boolean
true
Whether to show the number of rows checked in a toast message.
Boolean
false
Whether to allow the user to paste copied content into selected cell(s).
String
▼
String to render as the dropdown button. You can pass a span with an icon class.
Example
{
dropdownButton: '<span class="fa fa-chevron-down"></span>'
}
Array
When you hover over any column, you see the dropdown button which is used to perform certain actions for that column. This options allows you to pass an array of custom buttons with custom actions defined by you.
options = {
headerDropdown: [
{
label: 'Copy column contents',
action: function (column) {
// code to copy the column contents
}
},
}
Object
The events options is described in detailed in the next section.