Bootstrap DataTable
Posted by Superadmin on April 30 2023 16:31:08

Bootstrap DataTable

Bootstrap DataTable

Introduction to Bootstrap DataTable

The Bootstrap DataTable is an advanced plugin to combine advanced data operation of the table. The Bootstrap4 DataTable is an advanced design and modify the version of the bootstrap table. The Bootstrap4 DataTable provides JavaScript validation and cascading style sheet design without any configuration. It is searching, sorting, and paging of the table without any complicated coding.

Syntax:

The Bootstrap DataTable syntax of html page is below:

<table id = "daTable" class = "table table-bordered">
<thead>
<tr> <th> Header Name </th>
</thead>
<tbody>
<tr> <td> Header Information </td> </tr>
</tbody>
</table>

The Bootstrap DataTable JavaScript syntax is below:

<script>
$(document).ready(function() {
$('#daTable').DataTable();
} );
</script>

How do DataTable work in Bootstrap?

This file path is below:

<link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js">
</script>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>

The following link and source files are related to bootstrap4 datable.

<link rel = "stylesheet" href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap4.min.css">
<script src = "https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js">
</script>
<script src = "https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap4.min.js">
</script>

The table tag, Bootstrap4 table class, and table id name placed in the body section.

<table id="daTable" class="table table-bordered" >
<thead>
<tr>
<th>Name</th>
<th>position</th>
<th>Place</th>
</tr>
</thead>
<tbody>
<tr>
<td>emma thor</td>
<td>writer</td>
<td>NYK</td>
</tr>
</table>

The bootstrap DataTable JavaScript syntax is below:

<script>
$(document).ready(function() {
$('#daTable').DataTable();
} );
</script>

The basic working procedure is below:

<!DOCTYPE html>
<html>
<head>
<link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js
script>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<link rel = "stylesheet" href = "https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap4.min.css">
<script src = "https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js">
</script>
<script src = "https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap4.min.js">
</script>
</head>
<body>
<table id = "myTable" class = "table table-bordered" style = "width:100%">
<thead>
<tr>
<th> Name </th>
<th> Place </th>
<th> Position </th>
</tr>
</thead>
<tbody>
<tr>
<td> Emma thor </td>
<td> NYK </td>
<td> writer </td>
</tr>
</table>
<script>
$(document).ready(function() {
$('#myTable').DataTable();
} );
</script>
</body>
</html>

Examples

Given below are the examples mentioned:

Example #1

The basic example with output.

Code:

<!DOCTYPE html>
<html>
<head>
<link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js
script>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<link rel = "stylesheet" href = "https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap4.min.css">
<script src = "https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js">
</script>
<script src = "https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap4.min.js">
</script>
$(document).ready(function() {
$('#myTable').DataTable();
} );
</script>
</head>
<body>
<h1> Bootstrap Datatable </h1>
<table id = "myTable" class = "table table-bordered" style = "width: 100%">
<thead>
<tr>
<th> Name </th>
<th> Place </th>
<th> Position </th>
</tr>
</thead>
<tbody>
<tr>
<td> Emma Thor </td>
<td> NYK </td>
<td> Technical writer </td>
</tr>
<td> Merry Tyson </td>
<td> NYK </td>
<td> blog writer </td>
</tr>
</table>
</body>
</html>

Output:

Bootstrap DataTable 1

Explanation:

Example #2

With large amount of table content and output.

Code:

<html>
<head>
<link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js
script>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<link rel = "stylesheet" href = "https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap4.min.css">
<script src = "https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js">
</script>
<script src = "https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap4.min.js">
</script>
$(document).ready(function() {
$('#myTable').DataTable();
} );
</script>
</head>
<body>
<h1> Bootstrap Datatable </h1>
<table id = "myTable" class = "table table-bordered " style = "width:100%">
<thead>
<tr>
<th> Name </th>
<th> Place </th>
<th> Position </th>
</tr>
</thead>
<tbody>
<tr>
<td> Emma Thor </td>
<td> NYK </td>
<td> Technical writer </td>
</tr>
<td> Merry Tyson </td>
<td> NYK </td>
<td> blog writer </td>
</tr>
</tr>
<td> sofia </td>
<td> france </td>
<td> HR </td>
</tr>
<tr>
<td> olivia </td>
<td> landon </td>
<td> sales </td>
</tr>
<tr>
<td> radhakrishanan </td>
<td> chennai </td>
<td> animation </td>
</tr>
<tr>
<td> Adiison </td>
<td> pondecherry </td>
<td> blog writer </td>
</tr>
<tr>
<td> suhas </td>
<td> mumbai </td>
<td> tester </td>
</tr>
<tr>
<td> sangita </td>
<td> delhi </td>
<td> writer </td>
</tr>
<tr>
<td> Ram </td>
<td> pune </td>
<td> developer </td>
</tr>
<tr>
<td> josef </td>
<td> bijing </td>
<td> designer </td>
</tr>
</tr>
<td> josef </td>
<td> germany </td>
<td> co-ordinator </td>
</tr>
<tr>
<td> jyoti </td>
<td> pune </td>
<td> manager </td>
</tr>
<tr>
<td> amay </td>
<td> bengluru </td>
<td>  back-end coder </td>
</tr>
<tr>
<td> sujay </td>
<td> germany </td>
<td> front-end designer </td>
</tr>
<tr>
<td> jimmy jain </td>
<td> NYk </td>
<td> sales </td>
</tr>
<tr>
<td> avni gupta </td>
<td> france </td>
<td> marketing </td>
</tr>
<tr>
<td> john denmar </td>
<td> san Frans </td>
<td> developer </td>
</tr>
<tr>
<td> sania watt </td>
<td> paris </td>
<td> content writer </td>
</tr>
</table>
</body>
</html>

Output:

output come up with 10 shows entries

Bootstrap DataTable 3

Example #3

The Bootstrap striped table with search box implementation example and output.

Code:

<!DOCTYPE html>
<html>
<head>
<link rel = "stylesheet" href = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src = "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js
script>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js">
</script>
<link rel = "stylesheet" href = "https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap4.min.css">
<script src = "https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js">
</script>
<script src = "https://cdn.datatables.net/1.10.21/js/dataTables.bootstrap4.min.js">
</script>
$(document).ready(function() {
$('#myTable').DataTable();
} );
</script>
</head>
<body>
<h1> Bootstrap Datatable </h1>
<table id = "myTable" class = "table table-bordered table-striped" style = "width:100%">
<thead>
<tr>
<th> Name </th>
<th> Place </th>
<th> Position </th>
</tr>
</thead>
<tbody>
<tr>
<td> Emma Thor </td>
<td> NYK </td>
<td> Technical writer </td>
</tr>
<tr>
<td> josef </td>
<td> bijing </td>
<td> designer </td>
</tr>
</tr>
<td> josef </td>
<td> germany </td>
<td> co-ordinator </td>
</tr>
<tr>
<td> jyoti </td>
<td> pune </td>
<td> manager </td>
</tr>
<tr>
<td> jimmy jain </td>
<td> NYk </td>
<td> sales </td>
</tr>
<tr>
<td> john denmar </td>
<td> san Frans </td>
<td> developer </td>
</tr>
</table>
</body>
</html>

Output:

Output come up with searching “jo” characters in searching box.

striped table with search box implementation

Conclusion

It helps to sort table data without any complications. It reduces coding size and space by using one method. It is advance, user friendly, easy to understand component for the web application.