Version 6.3 Released!

Click to checkout the new features

Old Documentation
You are browsing documentation for an old version of Tabulator. Consider upgrading your project to Tabulator 6.3

Virtual DOM Documentation

As of version 3.0 tabulator renders its table using a Virtual DOM, this means that it only renders the rows you seen in the table (plus a few above and below the current view) and creates and destroys the rows as you scroll through the table.

The table below has 1000 rows loaded as they are needed as you scroll

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    columns:[
    {title:"Name", field:"name"},
    {title:"Progress", field:"progress", sorter:"number"},
    {title:"Gender", field:"gender"},
    {title:"Rating", field:"rating"},
    {title:"Favourite Color", field:"col"},
    {title:"Date Of Birth", field:"dob", align:"center"},
    ],
});

Fit To Data Documentation

Tables will automatically resize to fit the data

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    columns:[
    {title:"Name", field:"name"},
    {title:"Progress", field:"progress", align:"right", sorter:"number"},
    {title:"Gender", field:"gender"},
    {title:"Rating", field:"rating", align:"center"},
    {title:"Favourite Color", field:"col"},
    {title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
    {title:"Driver", field:"car", align:"center"},
    ],
});

Fit To Data and Fill Documentation

By setting the layout option to fitDataFill, the table will resize the columns to fit their data, and ensure that rows takeup the full width of the table.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    layout:"fitDataFill",
    height:"311px",
    columns:[
    {title:"Name", field:"name"},
    {title:"Progress", field:"progress", align:"right", sorter:"number"},
    {title:"Gender", field:"gender"},
    {title:"Rating", field:"rating", align:"center"},
    {title:"Favourite Color", field:"col"},
    ],
});

Fit To Width Documentation

By setting the layout option to fitColumns, the table will resize columns so that they fit perfectly inside the width of the container.

In this layout mode, columns without a width set are resized to fill any remaining space on the table. If all columns cannot fit on the table then a scrollbar will appear.

The widthGrow and widthShrink column definition properties can be used to set how much each column grows or shrinks by.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    columns:[
    {title:"Name", field:"name", width:200},
    {title:"Progress", field:"progress", align:"right", sorter:"number"},
    {title:"Gender", field:"gender", widthGrow:2},
    {title:"Rating", field:"rating", align:"center"},
    {title:"Favourite Color", field:"col", widthGrow:3},
    {title:"Date Of Birth", field:"dob", align:"center", sorter:"date", widthGrow:2},
    {title:"Driver", field:"car", align:"center"},
    ],
});

Responsive Layout Documentation

By setting the responsiveLayout option to "hide", the table will automatically hide/show columns to prevent the columns from exceeding the width of container.

If you resize the the width of the window you will see the number of columns change to ensure the data fits with the table. This option can be combined with fitColumns to make a table that gracefully responds to all display widths.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    responsiveLayout:"hide",
    columns:[
    {title:"Name", field:"name", width:200, responsive:0}, //never hide this column
    {title:"Progress", field:"progress", align:"right", sorter:"number", width:150},
    {title:"Gender", field:"gender", width:150, responsive:2}, //hide this column first
    {title:"Rating", field:"rating", align:"center", width:150},
    {title:"Favourite Color", field:"col", width:150},
    {title:"Date Of Birth", field:"dob", align:"center", sorter:"date", width:150},
    {title:"Driver", field:"car", align:"center", width:150},
    ],
});

Responsive Layout Collapsed List Documentation

By setting the responsiveLayout option to "collapse", the table will automatically collapse columns that don't fit on the table into a list of column titles and values.

If you resize the the width of the window you will see the number of columns change to ensure the data fits with the table and the collapsed list showing under each row.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitDataFill",
    responsiveLayout:"collapse",
    columns:[
    {formatter:"responsiveCollapse", width:30, minWidth:30, align:"center", resizable:false, headerSort:false},
    {title:"Name", field:"name", width:200, responsive:0},
    {title:"Progress", field:"progress", align:"right", sorter:"number", width:150},
    {title:"Gender", field:"gender", width:150, responsive:2},
    {title:"Rating", field:"rating", align:"center", width:150},
    {title:"Favourite Color", field:"col", width:150},
    {title:"Date Of Birth", field:"dob", align:"center", sorter:"date", width:150},
    {title:"Driver", field:"car", align:"center", width:150},
    ],
});

Automatic Column Generation Documentation

Tabulator can automatically work out the columns structure of simple tables by examining the data in the first row of the table.

If you set the autoColumns option to true, every time data is loaded into the table through the data option or through the setData function, Tabulator will examine the first row of the data and build columns to match that data.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//define data
var tabledata = [
    {id:1, name:"Oli Bob", location:"United Kingdom", gender:"male", rating:1, col:"red", dob:"14/04/1984"},
    {id:2, name:"Mary May", location:"Germany", gender:"female", rating:2, col:"blue", dob:"14/05/1982"},
    {id:3, name:"Christine Lobowski", location:"France", gender:"female", rating:0, col:"green", dob:"22/05/1982"},
    {id:4, name:"Brendon Philips", location:"USA", gender:"male", rating:1, col:"orange", dob:"01/08/1980"},
    {id:5, name:"Margret Marmajuke", location:"Canada", gender:"female", rating:5, col:"yellow", dob:"31/01/1999"},
    {id:6, name:"Frank Harbours", location:"Russia", gender:"male", rating:4, col:"red", dob:"12/05/1966"},
    {id:7, name:"Jamie Newhart", location:"India", gender:"male", rating:3, col:"green", dob:"14/05/1985"},
    {id:8, name:"Gemma Jane", location:"China", gender:"female", rating:0, col:"red", dob:"22/05/1982"},
    {id:9, name:"Emily Sykes", location:"South Korea", gender:"female", rating:1, col:"maroon", dob:"11/11/1970"},
    {id:10, name:"James Newman", location:"Japan", gender:"male", rating:5, col:"red", dob:"22/03/1998"},
];

//define table
var table = new Tabulator("#example-table", {
    data:tabledata,
    autoColumns:true,
});

Column Groups Documentation

By creating groups in the column definition array, you can create multi line headers with groups of columns.

You can use the columnVertAlign option to set how the text in your columns headers should be vertically aligned.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    columnVertAlign:"bottom", //align header contents to bottom of cell
    columns:[
    {title:"Name", field:"name", width:160},
    {//create column group
        title:"Work Info",
        columns:[
        {title:"Progress", field:"progress", align:"right", sorter:"number", width:100},
        {title:"Rating", field:"rating", align:"center", width:80},
        {title:"Driver", field:"car", align:"center", width:80},
        ],
    },
    {//create column group
        title:"Personal Info",
        columns:[
        {title:"Gender", field:"gender", width:90},
        {title:"Favourite Color", field:"col", width:140},
        {title:"Date Of Birth", field:"dob", align:"center", sorter:"date", width:130},
        ],
    },
    ],
});

Vertical Column Headers Documentation

If you are trying to fit a lot of narrow columns on your table, you can use the headerVertical column definition propery to change the orientation of the header text to vertical.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    columns:[
        {title:"Name", field:"name", headerSort:false, headerVertical:true},
        {title:"Progress", field:"progress", sorter:"number", align:"left", formatter:"progress",  editable:true, headerSort:false, headerVertical:true},
        {title:"Gender", field:"gender", headerSort:false, headerVertical:true},
        {title:"Rating", field:"rating", align:"center", headerSort:false, headerVertical:true},
        {title:"Date Of Birth", field:"dob", align:"center", sorter:"date", headerSort:false, headerVertical:true},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross", headerSort:false, headerVertical:true},
    ],
});

Frozen Columns Documentation

You can use the frozen property in a columns definition object to freeze that column in place during horizontal scrollling.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    columns:[
    {title:"Name", field:"name", width:250, frozen:true}, //frozen column
    {title:"Progress", field:"progress", sorter:"number", align:"left", formatter:"progress", width:200,  editable:true},
    {title:"Gender", field:"gender", width:150},
    {title:"Rating", field:"rating",  formatter:"star", align:"center", width:200},
    {title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
    {title:"Driver", field:"car", align:"center", formatter:"tickCross", width:150},
    ],
});

Frozen Rows Documentation

You can use the freeze function on a row component to freeze that row at the top of the table during vertical scrollling.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
	height:"311px",
	columns:[
	{title:"Name", field:"name", width:250},
	{title:"Progress", field:"progress", sorter:"number", align:"left", formatter:"progress", width:200,  editable:true},
	{title:"Gender", field:"gender", width:150},
	{title:"Rating", field:"rating",  formatter:"star", align:"center", width:200},
	{title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
	{title:"Driver", field:"car", align:"center", formatter:"tickCross", width:150},
	],
	dataLoaded:function(data){ //freeze first row on data load
		var firstRow = this.getRows()[0];

		if(firstRow){
			firstRow.freeze();
		}
	}
});

Nested Data Trees Documentation

You can use enable tree structures on nested data by setting the dataTree option to true in the table constructor.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    data:tableDataNested,
    dataTree:true,
    dataTreeStartExpanded:true,
    columns:[
    {title:"Name", field:"name", width:200, responsive:0}, //never hide this column
    {title:"Location", field:"location", width:150},
    {title:"Gender", field:"gender", width:150, responsive:2}, //hide this column first
    {title:"Favourite Color", field:"col", width:150},
    {title:"Date Of Birth", field:"dob", align:"center", sorter:"date", width:150},
    ],
});

Nested Table Data

var tableDataNested = [
    {name:"Oli Bob", location:"United Kingdom", gender:"male", col:"red", dob:"14/04/1984", _children:[
        {name:"Mary May", location:"Germany", gender:"female", col:"blue", dob:"14/05/1982"},
        {name:"Christine Lobowski", location:"France", gender:"female", col:"green", dob:"22/05/1982"},
        {name:"Brendon Philips", location:"USA", gender:"male", col:"orange", dob:"01/08/1980", _children:[
            {name:"Margret Marmajuke", location:"Canada", gender:"female", col:"yellow", dob:"31/01/1999"},
            {name:"Frank Harbours", location:"Russia", gender:"male", col:"red", dob:"12/05/1966"},
        ]},
    ]},
    {name:"Jamie Newhart", location:"India", gender:"male", col:"green", dob:"14/05/1985"},
    {name:"Gemma Jane", location:"China", gender:"female", col:"red", dob:"22/05/1982", _children:[
        {name:"Emily Sykes", location:"South Korea", gender:"female", col:"maroon", dob:"11/11/1970"},
    ]},
    {name:"James Newman", location:"Japan", gender:"male", col:"red", dob:"22/03/1998"},
];

Nested Tables

You can also use the rowFormatter callback to create tables nested in other tables.

You just need to make sure that the second tables data array is in a property of the first tables row data object, in this example we will use the property serviceHistory.

Loading Example...
Source Code

Data

 var nestedData = [
    {id:1, make:"Ford", model:"focus", reg:"P232 NJP", color:"white", serviceHistory:[
       {date:"01/02/2016", engineer:"Steve Boberson", actions:"Changed oli filter"},
       {date:"07/02/2017", engineer:"Martin Stevenson", actions:"Break light broken"},
    ]},
    {id:1, make:"BMW", model:"m3", reg:"W342 SEF", color:"red", serviceHistory:[
       {date:"22/05/2017", engineer:"Jimmy Brown", actions:"Aligned wheels"},
       {date:"11/02/2018", engineer:"Lotty Ferberson", actions:"Changed Oil"},
       {date:"04/04/2018", engineer:"Franco Martinez", actions:"Fixed Tracking"},
    ]},
]

JavaScript

//define table
var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    resizableColumns:false,
    data:nestedData,
    columns:[
        {title:"Make", field:"make"},
        {title:"Model", field:"model"},
        {title:"Registration", field:"reg"},
        {title:"Color", field:"color"},
    ],
    rowFormatter:function(row){
        //create and style holder elements
       var holderEl = document.createElement("div");
       var tableEl = document.createElement("div");

       holderEl.style.boxSizing = "border-box";
       holderEl.style.padding = "10px 30px 10px 10px";
       holderEl.style.borderTop = "1px solid #333";
       holderEl.style.borderBotom = "1px solid #333";
       

       tableEl.style.border = "1px solid #333";

       holderEl.appendChild(tableEl);

       row.getElement().appendChild(holderEl);

       var subTable = new Tabulator(tableEl, {
           layout:"fitColumns",
           data:row.getData().serviceHistory,
           columns:[
           {title:"Date", field:"date", sorter:"date"},
           {title:"Engineer", field:"engineer"},
           {title:"Action", field:"actions"},
           ]
       })
    },
});

Formatters Documentation

Tabulator allows you to format your data in a wide variety of ways, so your tables can display information in a more graphical and clear layout.

you can set formatters on a per column basis using the formatter option in the column data.

Tabulator comes with a number of preconfigured formatters including:

  • money - formats a number into a currency notation (eg. 1234567.8901 -> 1,234,567.89)
  • image - creates an img element wirh the src set as the value. (triggers the normalizeHeight function on the row on image load)
  • link - renders data as an anchor with a link to the given value
  • tick - displays a green tick if the value is (true|'true'|'True'|1) and an empty cell if not
  • tickCross - displays a green tick if the value is (true|'true'|'True'|1) and a red cross if not
  • color - sets the background color of the cell to the value. Can be any valid css colour eg. #ff0000, #f00, rgb(255,0,0), red, rgba(255,0,0,0), hsl(0, 100%, 50%)
  • star - displays a graphical 0-5 star rating based on integer values from 0-5
  • progress - displays a progress bar that fills the cell from left to right, using values 0-100 as a percentage of width
  • buttonTick - displays a tick icon on each row (for use as a button)
  • buttonCross - displays a cross icon on each row (for use as a button)
  • rownum - shows an incrementing row number for each row.

You can define a custom formatter function in the formatter option if you need more bespoke formatter functionality

You can create icon/button columns, by not specifying a field parameter in the column data and creating a custom formatter for the column contents. In the example below we have created a print button on the left of each row.

You can also set a row formatter using the rowFormatter option, this allows you to format the styling of the row as a whole

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Generate print icon
var printIcon = function(cell, formatterParams){ //plain text value
    return "<i class='fa fa-print'></i>";
};

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    rowFormatter:function(row){
        if(row.getData().col == "blue"){
            row.getElement().style.backgroundColor = "#1e3b20";
        }
    },
    columns:[
    {formatter:"rownum", align:"center", width:40},
    {formatter:printIcon, width:40, align:"center", cellClick:function(e, cell){alert("Printing row data for: " + cell.getRow().getData().name)}},
    {title:"Name", field:"name", width:150, formatter:function(cell, formatterParams){
       var value = cell.getValue();
        if(value.indexOf("o") > 0){
            return "<span style='color:#3FB449; font-weight:bold;'>" + value + "</span>";
        }else{
            return value;
        }
    }},
    {title:"Progress", field:"progress", formatter:"progress", formatterParams:{color:["#00dd00", "orange", "rgb(255,0,0)"]}, sorter:"number", width:100},
    {title:"Rating", field:"rating", formatter:"star", formatterParams:{stars:6}, align:"center", width:120},
    {title:"Driver", field:"car", align:"center", formatter:"tickCross", width:50},
    {title:"Col", field:"col" ,formatter:"color", width:50},
    {title:"Line Wraping", field:"lorem" ,formatter:"textarea"},
    {formatter:"buttonCross", width:30, align:"center"}
    ],
});

Row Formatter Documentation

If you are looking for a non grid based format to your table then you can use a row formatter to create custom row layouts.

You can use the rowFormatter callback to replace the contents of the row with any layout you like. In this example we will create a simple table in each row containing and image and some vertically centered text properties.

When replacing the entire contents of the row it is important to include only one column in your column definition array to ensure the table renders correctly. It is also advisable to enable fitColumns and disabled resizableColumns options.

Loading Example...
Source Code

CSS

/*Style row formatter contents*/
#example-table .tabulator-row table{
    vertical-align: middle;
    border-collapse:collapse;
}

#example-table .tabulator-row table img{
    border:2px solid #ccc;
}

#example-table .tabulator-row table tr td{
     border:none;
}

#example-table .tabulator-row table tr td:first-of-type{
    width:60px;
}

#example-table .tabulator-row table tr td div{
    padding:5px;
}

JavaScript

//Define some test data
var cheeseData = [
    {id:1, type:"Brie", rind:"mould", age:"4 weeks", color:"white", image:"brie.jpg"},
    {id:2, type:"Cheddar", rind:"none", age:"1 year", color:"yellow", image:"cheddar.jpg"},
    {id:3, type:"Gouda", rind:"wax", age:"6 months", color:"cream", image:"gouda.jpg"},
    {id:4, type:"Swiss", rind:"none", age:"9 months", color:"yellow", image:"swiss.jpg"},
]

//define Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    resizableColumns:false,
    columns:[
        {title:"Cheese", field:"type", sorter:"string"},
    ],
    rowFormatter:function(row){
        var element = row.getElement(),
        data = row.getData(),
        width = element.offsetWidth,
        rowTable, cellContents;

        //clear current row data
        while(element.firstChild) element.removeChild(element.firstChild);

        //define a table layout structure and set width of row
        rowTable = document.createElement("table")
        rowTable.style.width = (width - 18) + "px";

        rowTabletr = document.createElement("tr");

        //add image on left of row
        cellContents = "<td><img src='/sample_data/row_formatter/" + data.image + "'></td>";

        //add row data on right hand side
        cellContents += "<td><div><strong>Type:</strong> " + data.type + "</div><div><strong>Age:</strong> " + data.age + "</div><div><strong>Rind:</strong> " + data.rind + "</div><div><strong>Colour:</strong> " + data.color + "</div></td>"

        rowTabletr.innerHTML = cellContents;

        rowTable.appendChild(rowTabletr);

        //append newly formatted contents to the row
        element.append(rowTable);
    },
})

//Load Data
$("#example-table").tabulator("setData", cheeseData);

Custom Formatters

You can use external JavaScript libraries in any of your custom formatters. in this example we will use the popular piety.js library.

We will be passing an array of values into a field and then using a custom formatter to turn this array into a line or bar chart.

The Piety library can be downloaded from Git Hub.

Loading Example...
Source Code

HTML

<!-- Include piety library -->
<script src="piety.js"></script>

<!-- Element to hold Tabulator -->
<div id="example-table"></div>

JavaScript

//Formatter to generate charts
 var chartFormatter = function(cell, formatterParams, onRendered){
    var content = document.createElement("span");
    var values = cell.getValue();

    //invert values if needed
    if(formatterParams.invert){
        values = values.map(val => val * -1);
    }

    //add values to chart and style
    content.classList.add(formatterParams.type);
    content.innerHTML = values.join(",");

    //setup chart options
    var options = {
        width: 145,
    }

    if(formatterParams.fill){
        options.fill = formatterParams.fill
    }

    //instantiate piety chart after the cell element has been aded to the DOM
    onRendered(function(){
        peity(content, formatterParams.type,  options);
    });

    return content;
};

//Sample Data with array values for graph fields
var sparkData = [
    {id:1, name:"Oli Bob", line:[1, 20, 5, 3, 10, 13, 17, 15, 9, 11], bar:[1, 20, 5, 3, 10, 13, 17, 15, 9, 11], colored:[1, 20, -5, -3, 10, 13, 0, 15, 9, 11], inverted:[1, 20, 5, 3, 10, 13, 17, 15, 9, 11]},
    {id:2, name:"Mary May", line:[10, 12, 14, 16, 13, 9, 7, 11, 10, 13], bar:[10, 12, 14, 16, 13, 9, 7, 11, 10, 13], colored:[-10, 12, 14, 16, 13, 9, 7, 0, 10, 13], inverted:[10, 12, 14, 16, 13, 9, 7, 11, 10, 13]},
    {id:3, name:"Christine Lobowski", line:[1, 2, 5, 4, 1, 16, 4, 2, 1, 3], bar:[1, 2, 5, 4, 1, 16, 4, 2, 1, 3], colored:[1, 2, 5, 0, 1, 16, 4, 2, 1, 3], inverted:[1, 2, 5, 4, 1, 16, 4, 2, 1, 3]},
    {id:4, name:"Brendon Philips", line:[3, 7, 9, 1, 4, 8, 2, 6, 4, 2], bar:[3, 7, 9, 1, 4, 8, 2, 6, 4, 2], colored:[3, 7, 9, 1, 4, 8, 2, 6, 4, 2], inverted:[3, 7, 9, 1, 4, 8, 2, 6, 4, 2]},
    {id:5, name:"Margret Marmajuke", line:[1, 3, 1, 3, 3, 1, 1, 3, 1, 3], bar:[1, 3, 1, 3, 3, 1, 1, 3, 1, 3], colored:[1, -3, 1, 3, -3, 1, -1, 3, 1, 3], inverted:[1, 3, 1, 3, 3, 1, 1, 3, 1, 3]},
    {id:6, name:"Frank Harbours", line:[20, 17, 15, 11, 16, 9, 12, 14, 20, 12], bar:[20, 17, 15, 11, 16, 9, 12, 14, 20, 12], colored:[20, 17, 15, 11, 16, -9, 12, 14, 20, 12], inverted:[20, 17, 15, 11, 16, 9, 12, 14, 20, 12]},
    {id:7, name:"Jamie Newhart", line:[11, 7, 6, 12, 14, 13, 11, 10, 9, 6], bar:[11, 7, 6, 12, 14, 13, 11, 10, 9, 6], colored:[11, 7, 6, -12, 1-13, 11, 10, 9, 6], inverted:[11, 7, 6, 12, 14, 13, 11, 10, 9, 6]},
    {id:8, name:"Gemma Jane", line:[4, 17, 11, 12, 0, 5, 12, 14, 18, 11], bar:[4, 17, 11, 12, 0, 5, 12, 14, 18, 11], colored:[4, 17, 11, -12, 0, 5, 12, -14, 18, 11], inverted:[4, 17, 11, 12, 0, 5, 12, 14, 18, 11]},
    {id:9, name:"Emily Sykes", line:[11, 15, 19, 20, 17, 16, 16, 5, 3, 2], bar:[11, 15, 19, 20, 17, 16, 16, 5, 3, 2], colored:[11, 15, 19, -20, 17, 16, 16, -5, 3, 2], inverted:[11, 15, 19, 20, 17, 16, 16, 5, 3, 2]},
    {id:10, name:"James Newman", line:[1, 2, 3, 4, 5, 4, 2, 5, 9, 8], bar:[1, 2, 3, 4, 5, 4, 2, 5, 9, 8], colored:[1, 2, 0, -4, -5, -4, 2, 5, 9, 8], inverted:[1, 2, 3, 4, 5, 4, 2, 5, 9, 8]},
];


//Table Constructor
var example_table_sparkline = new Tabulator("#example-table-sparkline", {
    height:"311px",
    data:sparkData,
    columns:[
    {title:"Name", field:"name", width:190},
    {title:"Line Chart", field:"line", width:160, formatter:chartFormatter, formatterParams:{type:"line"}},
    {title:"Bar Chart", field:"bar", width:160, formatter:chartFormatter, formatterParams:{type:"bar"}},
    {title:"Coloured Bar Chart", field:"colored", width:160, formatter:chartFormatter, formatterParams:{type:"bar",  fill: function(value) {
        return value > 0 ? "green" : "red"
    }}},
    {title:"Inverted Bar Chart", field:"inverted", width:160, formatter:chartFormatter, formatterParams:{type:"bar", invert:true, fill: function(_, i, all) {
        var g = parseInt((i / all.length) * 255)
        return "rgb(255, " + g + ", 0)"
        }}},
    ],
});

Persistent Configuration Documentation

Tabulator can store a variety of table setup options so that each time a user comes back to the page, the table is laid out just as they left it

Try resizing (drag the right edge of a column header) or rearranging (drag the middle of a column header) the columns of this table, or sorting a column, then refresh the page. your new layout will persist.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    persistentLayout: true,
    persistentSort: true,
    persistenceID:"examplePerststance",
    columns:[
    {title:"Name", field:"name", width:200},
    {title:"Progress", field:"progress", width:100, sorter:"number"},
    {title:"Gender", field:"gender"},
    {title:"Rating", field:"rating", width:80},
    {title:"Favourite Color", field:"col"},
    {title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
    {title:"Driver", field:"car", align:"center", formatter:"tickCross"},
    ],
});

Column Calculations Documentation

Column calculations can be used to add a row of calculated values to the top or bottom of your table to display information such as the sum of a columns data.

There are two options that can be set in a column definition object to define a calculation, the topCalc option defines a calculation for the top of the column, and the bottomCalc defines a calculation for the bottom of the column. You can define, either, both or neither of the options.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    movableColumns:true,
    columns:[
        {title:"Name", field:"name", width:200},
        {title:"Progress", field:"progress", width:100, sorter:"number", bottomCalc:"avg", bottomCalcParams:{precision:3}},
        {title:"Gender", field:"gender"},
        {title:"Rating", field:"rating", width:80, bottomCalc:"avg"},
        {title:"Favourite Color", field:"col"},
        {title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross", topCalc:"count"},
    ],
});

AJAX Data Loading Documentation

Data can be loaded into the table from a remote URL using a JSON formatted string.

If you always request the same URL for your data then you can set it in the ajaxURL option when you create your Tabulator

Click the button below to load sample data via AJAX.

AJAX Controls
Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    placeholder:"No Data Set",
    columns:[
        {title:"Name", field:"name", sorter:"string", width:200},
        {title:"Progress", field:"progress", sorter:"number", formatter:"progress"},
        {title:"Gender", field:"gender", sorter:"string"},
        {title:"Rating", field:"rating", formatter:"star", align:"center", width:100},
        {title:"Favourite Color", field:"col", sorter:"string", sortable:false},
        {title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross", sorter:"boolean"},
    ],
});

//trigger AJAX load on "Load Data via AJAX" button click
$("#ajax-trigger").click(function(){
    table.setData("/exampledata/ajax");
});

Server Side PHP

//build data array
$data = [
    [id=>1, name=>"Billy Bob", progress=>"12", gender=>"male", height=>1, col=>"red", dob=>"", driver=>1],
    [id=>2, name=>"Mary May", progress=>"1", gender=>"female", height=>2, col=>"blue", dob=>"14/05/1982", driver=>true],
    [id=>3, name=>"Christine Lobowski", progress=>"42", height=>0, col=>"green", dob=>"22/05/1982", driver=>"true"],
    [id=>4, name=>"Brendon Philips", progress=>"125", gender=>"male", height=>1, col=>"orange", dob=>"01/08/1980"],
    [id=>5, name=>"Margret Marmajuke", progress=>"16", gender=>"female", height=>5, col=>"yellow", dob=>"31/01/1999"],
];

//return JSON formatted data
echo(json_encode($data));

AJAX Progressive Loading Documentation

You can use the ajaxProgressiveLoad option along with ajaxURL to progressivly load pages of data as the user scrolls down the table.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    ajaxURL:"/exampledata/ajaxprogressive",
    ajaxProgressiveLoad:"scroll",
    paginationSize:20,
    placeholder:"No Data Set",
    columns:[
        {title:"Name", field:"name", sorter:"string", width:200},
        {title:"Progress", field:"progress", sorter:"number", formatter:"progress"},
        {title:"Gender", field:"gender", sorter:"string"},
        {title:"Rating", field:"rating", formatter:"star", align:"center", width:100},
        {title:"Favourite Color", field:"col", sorter:"string", sortable:false},
        {title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross", sorter:"boolean"},
    ],
});

Server Side PHP

//build data array
$data = [
    [id=>1, name=>"Billy Bob", progress=>"12", gender=>"male", height=>1, col=>"red", dob=>"", driver=>1],
    [id=>2, name=>"Mary May", progress=>"1", gender=>"female", height=>2, col=>"blue", dob=>"14/05/1982", driver=>true],
    [id=>3, name=>"Christine Lobowski", progress=>"42", height=>0, col=>"green", dob=>"22/05/1982", driver=>"true"],
    [id=>4, name=>"Brendon Philips", progress=>"125", gender=>"male", height=>1, col=>"orange", dob=>"01/08/1980"],
    [id=>5, name=>"Margret Marmajuke", progress=>"16", gender=>"female", height=>5, col=>"yellow", dob=>"31/01/1999"],
];

//return JSON formatted data
echo(json_encode(["last_page"=>30, "data"=>$data]));

Load Table Data From Local File Documentation

Data can be loaded into the table from a local file using the setDataFromLocalFile function.

In the example below we also use the autoColumns feature to generate the column headers from the data as well, but you could just as easily predefine the columns

To start this example download the sample table data json file to your local computer.

Then click the button below to load sample data file.

Table Controls
Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:311,
    layout:"fitColumns",
    autoColumns:true,
    placeholder:"Awaiting Data, Please Load File",
});

//trigger AJAX load on "Load Data via AJAX" button click
$("#file-load-trigger").click(function(){
    table.setDataFromLocalFile();
});

Create from HTML Table Element Documentation

It is possible to convert a standard HTML Table element into a tabulator, pulling all the data directly from the table into the tabulator when it is created.

If you want to pull the column headers in from the table, you need to make sure that you have defiend a thead element with each column header in a th element. If you specify the width attribute on a header, then this will be set as the width of the column in the tabulator.

You can set any of the standard Tabulator options when you create your table this way, so can easily convert old tables to take advantage of the many features Tabulator has to offer.

Standard HTML Table:

Name Age Gender Height Favourite Color Date of Birth
Billy Bob 12 male 1 red 22/04/1994
Mary May 1 female 2 blue 14/05/1982

Converted to Tabulator:

Name Age Gender Height Favourite Color Date of Birth
Billy Bob 12 male 1 red 22/04/1994
Mary May 1 female 2 blue 14/05/1982
Source Code

HTML

<table id="example-table">
    <thead>
        <tr>
            <th width="200">Name</th>
            <th tabulator-align="center">Age</th>
            <th>Gender</th>
            <th>Height</th>
            <th width="150">Favourite Color</th>
            <th>Date of Birth</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Billy Bob</td>
            <td>12</td>
            <td>male</td>
            <td>1</td>
            <td>red</td>
            <td>22/04/1994</td>
        </tr>
        <tr>
            <td>Mary May</td>
            <td>1</td>
            <td>female</td>
            <td>2</td>
            <td>blue</td>
            <td>14/05/1982</td>
        </tr>
    </tbody>
</table>

JavaScript

 var table = new Tabulator("#example-table", {});

Data Reactivity Documentation

Data can be loaded into the table from a remote URL using a JSON formatted string.

If you always request the same URL for your data then you can set it in the ajaxURL option when you create your Tabulator

Click the button below to load sample data via AJAX.

Example Reactivity Controls
Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//define data
var tabledata = [
    {id:1, name:"Oli Bob", progress:12, gender:"male", rating:1, col:"red" },
    {id:2, name:"Mary May", progress:1, gender:"female", rating:2, col:"blue" },
    {id:3, name:"Christine Lobowski", progress:42, gender:"female", rating:0, col:"green" },
    {id:4, name:"Brendon Philips", progress:100, gender:"male", rating:1, col:"orange" },
    {id:5, name:"Margret Marmajuke", progress:16, gender:"female", rating:5, col:"yellow"},
];

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    reactiveData:true, //turn on data reactivity
    data:tabledata, //load data into table
    columns:[
        {title:"Name", field:"name", sorter:"string", width:200},
        {title:"Progress", field:"progress", sorter:"number", formatter:"progress"},
        {title:"Gender", field:"gender", sorter:"string"},
        {title:"Rating", field:"rating", formatter:"star", align:"center", width:100},
        {title:"Favourite Color", field:"col", sorter:"string", sortable:false},
    ],
});

//add row to bottom of table on button click
document.getElementById("reactivity-add").addEventListener("click", function(){
    tabledata.push({name:"IM A NEW ROW", progress:100, gender:"male"});
});

//remove bottom row from table on button click
document.getElementById("reactivity-delete").addEventListener("click", function(){
    tabledata.pop();
});

//update name on first row in table on button click
document.getElementById("reactivity-update").addEventListener("click", function(){
    tabledata[0].name = "IVE BEEN UPDATED";
});

Editable Data Documentation

Using the editable setting on each column, you can make a user editable table.

Any time a cell is edited it triggers the cellEdited callback, to allow you to process any changes.

You can call the getData method to get an array of all of the tables data, including any edits

This table features a custom date editor on the Date of Birth column.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Create Date Editor
var dateEditor = function(cell, onRendered, success, cancel){
    //cell - the cell component for the editable cell
    //onRendered - function to call when the editor has been rendered
    //success - function to call to pass thesuccessfully updated value to Tabulator
    //cancel - function to call to abort the edit and return to a normal cell

    //create and style input
    var cellValue = moment(cell.getValue(), "DD/MM/YYYY").format("YYYY-MM-DD"),
    input = document.createElement("input");

    input.setAttribute("type", "date");

    input.style.padding = "4px";
    input.style.width = "100%";
    input.style.boxSizing = "border-box";

    input.value = cellValue;

    onRendered(function(){
        input.focus();
        input.style.height = "100%";
    });

    function onChange(){
        if(input.value != cellValue){
            success(moment(input.value, "YYYY-MM-DD").format("DD/MM/YYYY"));
        }else{
            cancel();
        }
    }

    //submit new value on blur or change
    input.addEventListener("blur", onChange);

    //submit new value on enter
    input.addEventListener("keydown", function(e){
        if(e.keyCode == 13){
            onChange();
        }

        if(e.keyCode == 27){
            cancel();
        }
    });

    return input;
};


//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    columns:[
        {title:"Name", field:"name", width:150, editor:"input"},
        {title:"Location", field:"location", width:130, editor:"autocomplete", editorParams:{allowEmpty:true, showListOnEmpty:true, values:true}},
        {title:"Progress", field:"progress", sorter:"number", align:"left", formatter:"progress", width:140, editor:true},
        {title:"Gender", field:"gender", editor:"select", editorParams:{values:{"male":"Male", "female":"Female", "unknown":"Unknown"}}},
        {title:"Rating", field:"rating",  formatter:"star", align:"center", width:100, editor:true},
        {title:"Date Of Birth", field:"dob", align:"center", sorter:"date", width:140, editor:dateEditor},
        {title:"Driver", field:"car", align:"center", editor:true, formatter:"tickCross"},
    ],
});

Validate User Input Documentation

You can set validators on columns to ensure that any user input into your editable cells matches your requirements.

Validators can be applied by using the validator property in a columns definition object.

If the validation fails the tabulator-validation-fail class will be applied to the cell and the validationFailed callback will be triggered. The user will not be able to leave the cell until they input a valid value or cancel the edit (press escape).

The table below has the following validators applied to its columns:

  • Name - the field is required, it must have a value
  • Progress - minimum value of 0, maximum value of 100, must be a valid number
  • Gender - value must be either "male" or "female" and is required
  • Rating - minimum value of 0, maximum value of 5, must be a valid integer
  • Favourite Colour - minimum string length of 3, maximum string length of 10, bust be a string not a number

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    columns:[
        {title:"Name", field:"name", width:150, editor:"input", validator:"required"},
        {title:"Progress", field:"progress", sorter:"number", align:"left", editor:"input", editor:true,  validator:["min:0", "max:100", "numeric"]},
        {title:"Gender", field:"gender", editor:"input", validator:["required", "in:male|female"]},
        {title:"Rating", field:"rating",  editor:"input", align:"center", width:100, editor:"input", validator:["min:0", "max:5", "integer"]},
        {title:"Favourite Color", field:"col", editor:"input", validator:["minLength:3", "maxLength:10", "string"]},
    ],
    validationFailed:function(cell, value, validators){
        //cell - cell component for the edited cell
        //value - the value that failed validation
        //validatiors - an array of validator objects that failed

        //take action on validation fail
    },
});

Filter Data Documentation

Tabulator allows you to filter the table data by any field in the data set.

To set a filter you need to call the setFilter method, passing the field you wish to filter, the comparison type and the value to filter for

Tabulator comes with a number of filter comparison types including:

  • = - Displays only rows with data that is the same as the filter
  • < - displays rows with a value less than the filter value
  • <= - displays rows with a value less than or qual to the filter value
  • > - displays rows with a value greater than the filter value
  • >= - displays rows with a value greater than or qual to the filter value
  • != - displays rows with a value that is not equal to the filter value
  • like - displays any rows with data that contains the specified string anywhere in the specified field. (case insensitive)

Filter Parameters

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Custom filter example
function customFilter(data){
    return data.car && data.rating < 3;
}

//Trigger setFilter function with correct parameters
function updateFilter(){

    var filter = $("#filter-field").val() == "function" ? customFilter : $("#filter-field").val();

    if($("#filter-field").val() == "function" ){
        $("#filter-type").prop("disabled", true);
        $("#filter-value").prop("disabled", true);
    }else{
        $("#filter-type").prop("disabled", false);
        $("#filter-value").prop("disabled", false);
    }

    table.setFilter(filter, $("#filter-type").val(), $("#filter-value").val());
}

//Update filters on value change
$("#filter-field, #filter-type").change(updateFilter);
$("#filter-value").keyup(updateFilter);

//Clear filters on "Clear Filters" button click
$("#filter-clear").click(function(){
    $("#filter-field").val("");
    $("#filter-type").val("=");
    $("#filter-value").val("");

    table.clearFilter();
});

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    columns:[
        {title:"Name", field:"name", width:200},
        {title:"Progress", field:"progress", formatter:"progress", sorter:"number"},
        {title:"Gender", field:"gender"},
        {title:"Rating", field:"rating", formatter:"star", align:"center", width:100},
        {title:"Favourite Color", field:"col"},
        {title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross"},
    ],
});

Filter Data In Header Documentation

By settting the headerFilter parameter for a column you can add column based filtering directly into your table.

See the documentation for Header Filtering for more information.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//custom max min header filter
var minMaxFilterEditor = function(cell, onRendered, success, cancel, editorParams){

    var end;

    var container = document.createElement("span");

    //create and style inputs
    var start = document.createElement("input");
    start.setAttribute("type", "number");
    start.setAttribute("placeholder", "Min");
    start.setAttribute("min", 0);
    start.setAttribute("max", 100);
    start.style.padding = "4px";
    start.style.width = "50%";
    start.style.boxSizing = "border-box";

    start.value = cell.getValue();

    function buildValues(){
        success({
            start:start.value,
            end:end.value,
        });
    }

    function keypress(e){
        if(e.keyCode == 13){
            buildValues();
        }

        if(e.keyCode == 27){
            cancel();
        }
    }

    end = start.cloneNode();
    end.setAttribute("placeholder", "Max");

    start.addEventListener("change", buildValues);
    start.addEventListener("blur", buildValues);
    start.addEventListener("keydown", keypress);

    end.addEventListener("change", buildValues);
    end.addEventListener("blur", buildValues);
    end.addEventListener("keydown", keypress);


    container.appendChild(start);
    container.appendChild(end);

    return container;
 }

//custom max min filter function
function minMaxFilterFunction(headerValue, rowValue, rowData, filterParams){
    //headerValue - the value of the header filter element
    //rowValue - the value of the column in this row
    //rowData - the data for the row being filtered
    //filterParams - params object passed to the headerFilterFuncParams property

        if(rowValue){
            if(headerValue.start != ""){
                if(headerValue.end != ""){
                    return rowValue >= headerValue.start && rowValue <= headerValue.end;
                }else{
                    return rowValue >= headerValue.start;
                }
            }else{
                if(headerValue.end != ""){
                    return rowValue <= headerValue.end;
                }
            }
        }

    return true; //must return a boolean, true if it passes the filter.
}


var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    columns:[
        {title:"Name", field:"name", width:150, headerFilter:"input"},
        {title:"Progress", field:"progress", width:150, formatter:"progress", sorter:"number", headerFilter:minMaxFilterEditor, headerFilterFunc:minMaxFilterFunction},
        {title:"Gender", field:"gender", editor:"select", editorParams:{values:{"male":"Male", "female":"Female"}}, headerFilter:true, headerFilterParams:{values:{"male":"Male", "female":"Female", "":""}}},
        {title:"Rating", field:"rating", editor:"star", align:"center", width:100, headerFilter:"number", headerFilterPlaceholder:"at least...", headerFilterFunc:">="},
        {title:"Favourite Color", field:"col", editor:"input", headerFilter:"select", headerFilterParams:{values:true}},
        {title:"Date Of Birth", field:"dob", align:"center", sorter:"date",  headerFilter:"input"},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross",  headerFilter:"tickCross",  headerFilterParams:{"tristate":true},headerFilterEmptyCheck:function(value){return value === null}},
    ],
});

Sorters Documentation

By default Tabulator will attempt to guess which sorter should be applied to a column based on the data contained in the first row. It can determine sorters for strings, numbers, alphanumeric sequences and booleans, anything else will be treated as a string.

  • string - sorts column as strings of characters
  • number - sorts column as numbers (integer or float, will also handle numbers using "," separators)
  • alphanum - sorts column as alpha numeric code
  • boolean - sorts column as booleans
  • date - sorts column as dates
  • time - sorts column as times

To specify a sorter to be used on a column use the param property in the columns definition object

You can define a custom sorter functions in the sorter option if you need bespoke sorting functionality.

You can programmatically trigger a sort using the sort function.

Clicking on a column header will also trigger a sort of that column. You can sort by multiple columns by holding the ctrl or shift key when clicking on column headers.

Programmatic Sort Parameters
Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    columns:[
        {title:"Name", field:"name", width:200},
        {title:"Progress", field:"progress", align:"right", headerSortTristate:true},
        {title:"Gender", field:"gender", sorter:"string"},
        {title:"Rating", field:"rating",  align:"center", width:100},
        {title:"Favourite Color", field:"col", sortable:false, sorter:function(a,b){
            return String(a).toLowerCase().localeCompare(String(b).toLowerCase());
        }},
        {title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
        {title:"Driver", field:"car", align:"center", sorter:"boolean"},
    ],
});

//Trigger sort when "Trigger Sort" button is clicked
$("#sort-trigger").click(function(){
   table.setSort($("#sort-field").val(), $("#sort-direction").val());
});

Grouping Data Documentation

You can group rows together using the groupBy option. To group by a field, set this option to the name of the field.

To group by more complex operations you should pass a function that returns a string that represents the group.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    movableRows:true,
    groupBy:"gender",
    columns:[
        {title:"Name", field:"name", width:200},
        {title:"Progress", field:"progress", formatter:"progress", sorter:"number"},
        {title:"Gender", field:"gender"},
        {title:"Rating", field:"rating", formatter:"star", align:"center", width:100},
        {title:"Favourite Color", field:"col"},
        {title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross"},
    ],
});

Pagination Documentation

Tabulator allows you to paginate your data. simply set the pagination property to true.

If you have set the height of the table then the data will be automatically paginated to fit within the table.

If you wish to define how many rows should be shown on a page, set this in the paginationSize property. If you set the paginationSize without setting the height, the Tabulator will automatically resize to fit the data

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"292px",
    layout:"fitColumns",
    pagination:"local",
    paginationSize:6,
    paginationSizeSelector:[3, 6, 8, 10],
    movableColumns:true,
    columns:[
        {title:"Name", field:"name", width:200},
        {title:"Progress", field:"progress", formatter:"progress", sorter:"number"},
        {title:"Gender", field:"gender"},
        {title:"Rating", field:"rating", formatter:"star", align:"center", width:100},
        {title:"Favourite Color", field:"col"},
        {title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross"},
    ],
});

Selectable Rows Documentation

Using the selectable option, you can allow users to select rows in the table via a number of different routes:

  • Clicking on a row, to toggle its state.
  • Holding down the shift key and click dragging over a number of rows to toggle the state of all rows the cursor passes over.
  • Programmatically with the selectRow and deselectRow functions.

Selection Controls
Selected: 0
Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    selectable:true, //make rows selectable
    columns:[
	    {title:"Name", field:"name", width:200},
	    {title:"Progress", field:"progress", width:100, align:"right", sorter:"number"},
	    {title:"Gender", field:"gender", width:100},
	    {title:"Rating", field:"rating", align:"center", width:80},
	    {title:"Favourite Color", field:"col"},
	    {title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
	    {title:"Driver", field:"car", align:"center", width:100},
    ],
    rowSelectionChanged:function(data, rows){
        //update selected row counter on selection change
    	$("#select-stats span").text(data.length);
    },
});

//select row on "select" button click
$("#select-row").click(function(){
    table.selectRow(1);
});

//deselect row on "deselect" button click
$("#deselect-row").click(function(){
    table.deselectRow(1);
});

//select row on "select all" button click
$("#select-all").click(function(){
    table.selectRow();
});

//deselect row on "deselect all" button click
$("#deselect-all").click(function(){
    table.deselectRow();
});

Add / Delete Rows Documentation

Tablulator allows you to add new rows, delete existing rows and clear all table data with ease.

Row Controls
Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    addRowPos:"bottom",
    columns:[
        {title:"Name", field:"name", width:200, editor:"input"},
        {title:"Progress", field:"progress", width:100, align:"right", sorter:"number", editor:"input"},
        {title:"Gender", field:"gender", editor:"input"},
        {title:"Rating", field:"rating", align:"center", width:80, editor:"input"},
        {title:"Favourite Color", field:"col", editor:"input"},
        {title:"Date Of Birth", field:"dob", align:"center", sorter:"date", editor:"input"},
        {title:"Driver", field:"car", align:"center", editor:"input"},
    ],
});

//Add row on "Add Row" button click
$("#add-row").click(function(){
    table.addRow({});
});

//Delete row on "Delete Row" button click
$("#del-row").click(function(){
    table.deleteRow(1);
});

//Clear table on "Empty the table" button click
$("#clear").click(function(){
    table.clearData()
});

//Reset table contents on "Reset the table" button click
$("#reset").click(function(){
    table.setData(tabledata);
});

Movable Rows Documentation

Using the movableRows property you can allow the user to move rows around the table by clicking and dragging.

By default this allows the user to drag anywhere on the row, in this example we use the rowHandle property in a column definition to create a row handle that can be used for dragging rows.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    movableRows:true,
    columns:[
        {rowHandle:true, formatter:"handle", headerSort:false, frozen:true, width:30, minWidth:30},
        {title:"Name", field:"name", width:150},
        {title:"Progress", field:"progress", formatter:"progress", sorter:"number"},
        {title:"Gender", field:"gender"},
        {title:"Rating", field:"rating", formatter:"star", formatterParams:{stars:6}, align:"center", width:120},
        {title:"Favourite Color", field:"col"},
        {title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross"},
    ],
    rowMoved:function(row){
        console.log("Row: " + row.getData().name + " has been moved");
    }
});

Movable Rows With Row Groups Documentation

By using the groupValues property to define a series of groups, you can create a table that allows users to drag rows between groups, including empty groups.

Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    movableRows:true,
    groupBy:"col",
    groupValues:[["green", "blue", "purple"]]
    columns:[
        {rowHandle:true, formatter:"handle", headerSort:false, frozen:true, width:30, minWidth:30},
        {title:"Name", field:"name", width:150},
        {title:"Progress", field:"progress", formatter:"progress", sorter:"number"},
        {title:"Gender", field:"gender"},
        {title:"Rating", field:"rating", formatter:"star", formatterParams:{stars:6}, align:"center", width:120},
        {title:"Favourite Color", field:"col"},
        {title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross"},
    ],
});

Movable Rows Between Tables Documentation

Using the movableRowsConnectedTables property you can set the tables that can receive rows from another table.

In the example below, try dragging rows from the left table to the right table.

Loading Example...
Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Table to move rows from
var table = new Tabulator("#example-table-sender", {{
    height:311,
    layout:"fitColumns",
    movableRows:true,
    movableRowsConnectedTables:"#example-table-receiver",
    movableRowsReceiver: "add",
    movableRowsSender: "delete",
    placeholder:"All Rows Moved",
    data:tabledata,
    columns:[
        {title:"Name", field:"name"},
    ],
});

//Table to move rows to
var table = new Tabulator("#example-table-receiver", {
    height:311,
    layout:"fitColumns",
    placeholder:"Drag Rows Here",
    data:[],
    columns:[
        {title:"Name", field:"name"},
    ],
});

Download Table Data Documentation

Tabulator allows you to download the table data as a file directly from your browser, no server needed.

The download will contain the text values of all data currently visible in the table, matching the current column layout, column titles, sorting and filtering.

Download Controls
Loading Example...
Source Code

XLSX Script Includes

<script type="text/javascript" src="https://oss.sheetjs.com/sheetjs/xlsx.full.min.js"></script>

PDF Script Includes

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.5/jspdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.0.5/jspdf.plugin.autotable.js"></script>

HTML

<div id="example-table"></div>

JavaScript

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    columns:[
        {title:"Name", field:"name", width:200},
        {title:"Progress", field:"progress", width:100, sorter:"number"},
        {title:"Gender", field:"gender"},
        {title:"Rating", field:"rating", width:80},
        {title:"Favourite Color", field:"col"},
        {title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross"},
    ],
});

//trigger download of data.csv file
$("#download-csv").click(function(){
    table.download("csv", "data.csv");
});

//trigger download of data.json file
$("#download-json").click(function(){
    table.download("json", "data.json");
});

//trigger download of data.xlsx file
$("#download-xlsx").click(function(){
    table.download("xlsx", "data.xlsx", {sheetName:"My Data"});
});

//trigger download of data.pdf file
$("#download-pdf").click(function(){
    table.download("pdf", "data.pdf", {
        orientation:"portrait", //set page orientation to portrait
        title:"Example Report", //add title to report
    });
});

Clipboard Documentation

Using the clipboard option, you can allow users to copy and paste from your table

In the example below, try clciking anywhere in the table then using the ctrl + c key combination to copy the table, then pase into any spreadsheet application like Excel or Google sheets.

Then try changing that data, copying it then pasting it back into this table with thectrl + v key combination. You should see it replace the existing table data with your updated data set.

Loading Example...
Source Code

JavaScript

//Build Tabulator
var table = new Tabulator("#example-table", {
     height:"311px",
     data:tabledata,
     clipboard:true,
     clipboardPasteAction:"replace",
     columns:[
         {title:"Name", field:"name", width:200},
         {title:"Progress", field:"progress", width:100, sorter:"number"},
         {title:"Gender", field:"gender"},
         {title:"Rating", field:"rating", width:80},
         {title:"Favourite Color", field:"col"},
         {title:"Date Of Birth", field:"dob", align:"center", sorter:"date"},
         {title:"Driver", field:"car", align:"center", formatter:"tickCross"},
     ],
 });

Interaction History Documentation

By setting the history option to true, you can make the table track any user changes to the table.

You can use the undo and redo functions to move through the users interaction history, undoing cell edits, row additions or deletions.

As long as the table is in focus (but not being edited) you can also use the ctrl + z and ctrl + y keyboard shortcuts to undo and redo actions.

The example below has an editable names column, try making some changes to soe of the names and then use the history functions to undo and redo the changes.

History Controls
Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    history:true,
    columns:[
    {title:"Name", field:"name", width:200, editor:"input"},
    {title:"Progress", field:"progress", align:"right", editor:"input"},
    {title:"Gender", field:"gender", editor:"input"},
    {title:"Rating", field:"rating",  align:"center", width:100},
    {title:"Favourite Color", field:"col"},
    {title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
    {title:"Driver", field:"car", align:"center", sorter:"boolean"},
    ],
});

//undo button
$("#history-undo").on("click", function(){
  table.undo();
});

//redo button
$("#history-redo").on("click", function(){
   table.redo();
});

Localization Documentation

You can localize the content of your tables to meet the needs of your regional users. Any number of language options can be configured for column headers and pagination controls.

Language Controls
Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

//Build Tabulator
var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    pagination:"local",
    langs:{
        "fr-fr":{ //French language definition
            "columns":{
                "name":"Nom",
                "progress":"Progression",
                "gender":"Genre",
                "rating":"Évaluation",
                "col":"Couleur",
                "dob":"Date de Naissance",
            },
            "pagination":{
                "first":"Premier",
                "first_title":"Première Page",
                "last":"Dernier",
                "last_title":"Dernière Page",
                "prev":"Précédent",
                "prev_title":"Page Précédente",
                "next":"Suivant",
                "next_title":"Page Suivante",
            },
        },
        "de-de":{ //German language definition
            "columns":{
                "name":"Name",
                "progress":"Fortschritt",
                "gender":"Genre",
                "rating":"Geschlecht",
                "col":"Farbe",
                "dob":"Geburtsdatum",
            },
            "pagination":{
                "first":"Zuerst",
                "first_title":"Zuerst Seite",
                "last":"Last",
                "last_title":"Letzte Seite",
                "prev":"Zurück",
                "prev_title":"Zurück Seite",
                "next":"Nächster",
                "next_title":"Nächster Seite",
            },
        },
    },
    columns:[
        {title:"Name", field:"name"},
        {title:"Progress", field:"progress", sorter:"number"},
        {title:"Gender", field:"gender"},
        {title:"Rating", field:"rating"},
        {title:"Favourite Color", field:"col"},
        {title:"Date Of Birth", field:"dob"},
    ],
});

//set locale to French
$("#lang-french").click(function(){
    table.setLocale("fr-fr");
});

//set locale to German
$("#lang-german").click(function(){
    table.setLocale("de-de");
});

//set default locale
$("#lang-default").click(function(){
    table.setLocale("");
});

Callbacks Documentation

Tabulator features a range of callbacks to allow you to handle user interaction.

  • Cell Click - The cell click callback is triggered when a user left clicks on a cell, it can be set on a per column basis using the cellClick option in the columns data. (left click any cell in the gender column in this example)
  • Row Click - The row click callback is triggered when a user clicks on a row, it can be set globally, by setting therowClickoption when you create your Tabulator. (left click any row in this example)
  • Row Context Menu - The row context callback is triggered when a user right clicks on a row, it can be set globally, by setting the rowContext option when you create your Tabulator. (right click any row in this example)
  • Data Loaded - The data loaded callback is triggered when a new set of data is loaded into the table, it can be set globally, by setting the dataLoaded option when you create your
Loading Example...
Source Code

HTML

<div id="example-table"></div>

JavaScript

var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    columns:[
        {title:"Name", field:"name", sorter:"string", width:150},
        {title:"Progress", field:"progress", sorter:"number", align:"right", formatter:"progress"},
        {title:"Gender", field:"gender", width:100, sorter:"string", cellClick:function(e, cell){alert("cell clicked - " + cell.getValue())}},
        {title:"Rating", field:"rating", formatter:"star", align:"center", width:100},
        {title:"Favourite Color", field:"col", sorter:"string", sortable:false},
        {title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross", sorter:"boolean"},
    ],
    rowClick:function(e, row){
        alert("Row " + row.getIndex() + " Clicked!!!!")
    },
    rowContext:function(e, row){
        alert("Row " + row.getIndex() + " Context Clicked!!!!")
    },
});

Theming Documentation

Tabulator is styled using a full set of CSS classes, making theming of the table very simple. A full list of these can be found here.

A LESS file is also provided, containing a set of variables to make generating your own theme even easier. This can be found in tabulator.less

Tabulator comes with a number of packaged themes in the /dist/css/ directory of the package. To use one of these simply include the matching css file instead of the default tabulator.css

Standard Theme

The standard generic table theme. This can be found in /dist/css/tabulator.min.css

Loading Example...
Source Code

HTML

<link href="/dist/css/tabulator.min.css" rel="stylesheet">

Simple Theme

A plain, simplistic layout showing only basic grid lines. This can be found in /dist/css/tabulator_simple.min.css

Loading Example...
Source Code

HTML

<link href="/dist/css/tabulator_simple.min.css" rel="stylesheet">

Midnight Theme

A dark, stylish layout using simple shades of grey. This can be found in /dist/css/tabulator_midnight.min.css

Loading Example...
Source Code

HTML

<link href="/dist/css/tabulator_midnight.min.css" rel="stylesheet">

Modern Theme

A neat, stylish layout using one primary color. This color can be set in the @primary variable in the /dist/css/tabulator_modern.less file to alter the style to match your colour scheme. This can be found in /dist/css/tabulator_modern.min.css

Loading Example...
Source Code

HTML

<link href="/dist/css/tabulator_modern.min.css" rel="stylesheet">

Bootstrap 3 Theme

Match Tabulator to the standard Bootstrap 3 theme /dist/css/bootstrap/tabulator_bootstrap.min.css

Loading Example...
Source Code

HTML

<link href="/dist/css/bootstrap/tabulator_bootstrap.min.css" rel="stylesheet">

Bootstrap 4 Theme

Match Tabulator to the standard Bootstrap 4 theme /dist/css/bootstrap/tabulator_bootstrap4.min.css

Loading Example...
Source Code

HTML

<link href="/dist/css/bootstrap/tabulator_bootstrap4.min.css" rel="stylesheet">

Semantic UI Theme

Match Tabulator to the standard Semantic UI theme /dist/css/semantic-ui/tabulator_semantic-ui.min.css

Loading Example...
Source Code

HTML

<link href="/dist/css/semantic-ui/tabulator_semantic-ui.min.css" rel="stylesheet">

Bulma Theme

Match Tabulator to the standard Bulma theme /dist/css/bulma/tabulator_bulma.min.css

Loading Example...
Source Code

HTML

<link href="/dist/css/bulma/tabulator_bulma.min.css" rel="stylesheet">

Manually Adjusted Theme

You can override the default tabulator styling in document, or simply edit the provided tabulator.min.css file to make your own custom theme.

Loading Example...
Source Code

HTML

<div id="example-table-theme"></div>

CSS

/*Theme the Tabulator element*/
#example-table-theme{
    background-color:#ccc;
    border: 1px solid #333;
    border-radius: 10px;
}

/*Theme the header*/
#example-table-theme .tabulator-header {
    background-color:#333;
    color:#fff;
}

/*Allow column header names to wrap lines*/
#example-table-theme .tabulator-header .tabulator-col,
#example-table-theme .tabulator-header .tabulator-col-row-handle {
    white-space: normal;
}

/*Color the table rows*/
#example-table-theme .tabulator-tableHolder .tabulator-table .tabulator-row{
    color:#fff;
    background-color: #666;
}

/*Color even rows*/
    #example-table-theme .tabulator-tableHolder .tabulator-table .tabulator-row:nth-child(even) {
    background-color: #444;
}

JavaScript

var table = new Tabulator("#example-table-theme", {
    height:"331px",
    layout:"fitColumns",
    tooltipsHeader: false,
    columns:[
        {title:"Name", field:"name", sorter:"string", width:150},
        {title:"Progress", field:"progress", sorter:"number", align:"right", formatter:"progress"},
        {title:"Gender", field:"gender", width:100, sorter:"string", cellClick:function(e, cell){alert("cell clicked - " + cell.getValue())}},
        {title:"Rating", field:"rating", formatter:"star", align:"center", width:100},
        {title:"Favourite Color", field:"col", width:100, sorter:"string", sortable:false},
        {title:"Date Of Birth", field:"dob", width:100, sorter:"date", align:"center"},
        {title:"Driver", field:"car", align:"center", formatter:"tickCross", sorter:"boolean"},
    ],
});
Donate