Simple DataTables Example

Eugene Jul 31, 2026

DataTables is a highly flexible and feature-rich library for displaying tabular data on the web. It's widely used due to its simplicity and ease of use. Let's explore a simple example of DataTables to get you started.

Applying UX Principles to Data Tables
Applying UX Principles to Data Tables

In this article, we'll create a basic HTML table and transform it into an interactive table using DataTables. We'll cover the essential steps, including including the DataTables library, initializing the plugin, and customizing the table's appearance.

29 Free CSS3 & HTML Table Templates 2026 - Colorlib
29 Free CSS3 & HTML Table Templates 2026 - Colorlib

Setting Up the Environment

First, you need to include the DataTables library in your project. You can download it from the official website or use a CDN. For this example, we'll use the CDN version.

the list of users is shown in this screenshot
the list of users is shown in this screenshot

Add the following script tag in the head or body section of your HTML file:

```html ```

Creating the HTML Table

CSS Tables: Best Free Responsive Data Templates
CSS Tables: Best Free Responsive Data Templates

Next, create a simple HTML table with some data. For this example, let's use a table with information about different countries.

Here's a simple HTML table structure:

```html

Country Capital Population
USA Washington, D.C. 331,002,651
Canada Ottawa 37,589,262
Mexico Mexico City 128,932,753

Excel Pivot Table Explained (Part 1) | Easy Guide for Beginners with Example
Excel Pivot Table Explained (Part 1) | Easy Guide for Beginners with Example

```

Initializing DataTables

Now that we have our table, let's initialize DataTables. Add the following JavaScript code to your file:

```javascript $(document).ready( function () { $('#countries').DataTable(); } ); ```

Download Data Table & Pricing Table PowerPoint
Download Data Table & Pricing Table PowerPoint

This code waits for the document to be ready, then selects the table with the ID "countries" and initializes DataTables on it.

Customizing the Table

20 Creative Table UI Design Examples You Should Know in 2021
20 Creative Table UI Design Examples You Should Know in 2021
25,200+ Excel Table Stock Illustrations, Royalty-Free Vector Graphics & Clip Art - iStock
25,200+ Excel Table Stock Illustrations, Royalty-Free Vector Graphics & Clip Art - iStock
Simple Data Tables Easter Math Worksheet Answer Key | Woo! Jr. Kids Activities : Children's Publishing
Simple Data Tables Easter Math Worksheet Answer Key | Woo! Jr. Kids Activities : Children's Publishing
SQL ORDER BY Explained with Examples | Sort Data in SQL
SQL ORDER BY Explained with Examples | Sort Data in SQL
Table Keynote Templates - 20 best design infographic templates
Table Keynote Templates - 20 best design infographic templates
10 Free Bootstrap Datatable & CSS Table Templates – uiCookies
10 Free Bootstrap Datatable & CSS Table Templates – uiCookies
SQL SUM() Explained with Examples | Beginner SQL Tutorial
SQL SUM() Explained with Examples | Beginner SQL Tutorial
Simple Company Business Report Presentation Template
Simple Company Business Report Presentation Template
Financial Milestone Bookkeeper Daily Planner Google Sheets Template with Automated Dashboard 📂
Financial Milestone Bookkeeper Daily Planner Google Sheets Template with Automated Dashboard 📂
SQL CTE Explained with Examples | Common Table Expression Tutorial
SQL CTE Explained with Examples | Common Table Expression Tutorial
Pricing Tables: Examples And Best Practices — Smashing Magazine
Pricing Tables: Examples And Best Practices — Smashing Magazine
Dashboard
Dashboard
STANDARD DEVIATION
STANDARD DEVIATION
Data Table UI Design Guide & 30+ Examples
Data Table UI Design Guide & 30+ Examples
How to Create a Data Table with 3 Variables - 2 Examples - ExcelDemy
How to Create a Data Table with 3 Variables - 2 Examples - ExcelDemy
a blank sign up sheet with the number of items in it
a blank sign up sheet with the number of items in it
SQL GROUP BY Explained with Examples | Beginner SQL Tutorial
SQL GROUP BY Explained with Examples | Beginner SQL Tutorial
SQL Subqueries Explained with Examples | Beginner SQL Tutorial
SQL Subqueries Explained with Examples | Beginner SQL Tutorial
Таблицы ценообразования веб-элемент | Премиум векторы
Таблицы ценообразования веб-элемент | Премиум векторы
a table with two pricing cards and the words plans for every level of productivity
a table with two pricing cards and the words plans for every level of productivity

DataTables offers numerous customization options. Let's explore a couple of them.

Adding a Search Box

By default, DataTables adds a search box at the top right corner of the table. However, you can customize its position or style. To add a search box at the top left, use the following code:

```javascript $('#countries').DataTable( { dom: 'Bfrtip', buttons: [ 'copy', 'excel', 'pdf' ] } ); ```

This code also adds buttons for copying, exporting to Excel, and generating a PDF of the table.

Changing the Pagination Style

DataTables uses a simple pagination style by default. You can change this to a more advanced style using the following code:

```javascript $('#countries').DataTable( { "pagingType": "full_numbers" } ); ```

This code changes the pagination style to "full_numbers", which includes numbers, first and last page links, and next and previous page links.

With these simple steps, you've created an interactive table using DataTables. You can further customize the table's appearance and behavior using various options and plugins offered by DataTables. Happy coding!