
<a href="https://vuejsexamples.com/content/images/2017/09/A-fancy-Materialize-CSS-datatable-VueJS-component.png">image source</a>
This tutorial I will discuss a library that is very useful to display data in the form of tables, this library is also very much in use for web applications related to admnistrasi and relate data. the documentation and features in it are very complete. just start we start how to use it and what are the features in it
#### What Will I Learn?
- Use Jquery
- Implement datatables
- Customize datatables
#### Requirements
- Localhost (xampp,wampp, or etc )
- Internet Connection
- Basic Html & jquery
#### Difficulty
- Basic
#### Tutorial Contents
The first step we must create a file that is in our localhost folder, here I create a folder named <b>developments</b> and create <b>index.html</b> file. Because <a href="https://datatables.net">datatables.net</a> is a library of jquery, then we have to import jquery first. to import jquery , you can go to the official website of jquery https://jquery.com/
and please select the jqeuery version you want. In this tutorial I am using jquery version of jquery-3.2.1.min.js. grab the minified jquery to make it lighter. this is my <b>index.html</b>
``` html
<!DOCTYPE html>
<html>
<head>
<title>Data table for web apps</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="https://fonts.googleapis.com/css?family=Alegreya+Sans" rel="stylesheet">
</head>
<body>
<style type="text/css">
*{
padding: 0px;
margin: 0px;
}
html,body{
width: 100%;
font-family: 'Alegreya Sans', sans-serif;
}
</style>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
</body>
</html>
```
<code>< script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous" >< /script ></code> : Import Jquery with CDN version jquery-3.2.1.min.js
### Implement datatables
Before we start using the library datatables, we must import it first, with munggunakan CDN or you can download it, but more use it via CDN.
there are two that we must import from library datatables, they are <b>css</b> and <b>javascript</b>.
<li><b>Import Css datatables</b></li>
You can add <code>< link rel = "stylesheet" type = "text / css" href = "https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" ></code> before the <code>< /head ></code> closing tag.
<li><b>Import Javascript datatables</b></li>
you can add script <code>< script type = "text / javascript" src = "https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"> </ script ></code> after you import jquery, it's important to remember the location of the script library datatable under the jquery script for, the syntax in the library can be read.
<li><b>Make table html</b></li>
After we import datatables now we can use it, i will create a table in html.
<table id="datatable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>$170,750</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>$86,000</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Senior Javascript Developer</td>
<td>Edinburgh</td>
<td>22</td>
<td>2012/03/29</td>
<td>$433,060</td>
</tr>
<tr>
<td>Airi Satou</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>33</td>
<td>2008/11/28</td>
<td>$162,700</td>
</tr>
<tr>
<td>Brielle Williamson</td>
<td>Integration Specialist</td>
<td>New York</td>
<td>61</td>
<td>2012/12/02</td>
<td>$372,000</td>
</tr>
<tr>
<td>Herrod Chandler</td>
<td>Sales Assistant</td>
<td>San Francisco</td>
<td>59</td>
<td>2012/08/06</td>
<td>$137,500</td>
</tr>
<tr>
<td>Rhona Davidson</td>
<td>Integration Specialist</td>
<td>Tokyo</td>
<td>55</td>
<td>2010/10/14</td>
<td>$327,900</td>
</tr>
<tr>
<td>Colleen Hurst</td>
<td>Javascript Developer</td>
<td>San Francisco</td>
<td>39</td>
<td>2009/09/15</td>
<td>$205,500</td>
</tr>
<tr>
<td>Sonya Frost</td>
<td>Software Engineer</td>
<td>Edinburgh</td>
<td>23</td>
<td>2008/12/13</td>
<td>$103,600</td>
</tr>
<tr>
<td>Jena Gaines</td>
<td>Office Manager</td>
<td>London</td>
<td>30</td>
<td>2008/12/19</td>
<td>$90,560</td>
</tr>
<tr>
<td>Quinn Flynn</td>
<td>Support Lead</td>
<td>Edinburgh</td>
<td>22</td>
<td>2013/03/03</td>
<td>$342,000</td>
</tr>
<tr>
<td>Charde Marshall</td>
<td>Regional Director</td>
<td>San Francisco</td>
<td>36</td>
<td>2008/10/16</td>
<td>$470,600</td>
</tr>
</tbody>
</table>
https://res.cloudinary.com/hpiynhbhq/image/upload/v1516676329/nxodxyrbg5g2cid0xnzm.png
<li><b>Use and Define Datatables in Javascript</b></li>
Now that we have created a table in our html structure, we will define and use libraries in this way.
<pre><code>
< script type="text/javascript" >
$(document).ready(function() {
$('#datatables').DataTable();
});
< /script >
</code>
</pre>
<code>$('#datatables').DataTable();</code> : We named our <b>< table >< /table ></b> element with datatable id, so id that we use to define which element will use library datatables.
<br /><b>Use Library Datatables</b>

<br /><b>Not Use Library Datatables</b>
https://res.cloudinary.com/hpiynhbhq/image/upload/v1516677186/gpxnegznuqoodwchwcbh.png
### Customize datatables
There is a lot of customization that we can do in datatables. if you want complete documentation please visit their official website https://datatables.net. But in this tutorial I will only discuss some of them
<li><b>Feature enable / disable</b></li>
In datatable we can choose to enable and disable the property we want. for example we have datatables. by default datatable features search, order, and page.
https://res.cloudinary.com/hpiynhbhq/image/upload/v1516724581/bwyacvoubum9mpnj0abd.png
and now i will use featur enable/disable with javascript configuration like this.
<pre><code>
$(document).ready(function(){
$('#datatables').DataTable({
"paging": false,
"ordering": false,
"info": false
});
});
</code>
</pre>
https://res.cloudinary.com/hpiynhbhq/image/upload/v1516724810/ughrucx0jdoqzbblwrk6.png
we can see the features paging, info, ordering no longer appear because it has been disabled
<br />
<br />
<li><b>Hidden Columns</b></li>
The following table is not hidden.
https://res.cloudinary.com/hpiynhbhq/image/upload/v1516725327/amxij694zgm5f1snfqfp.png
<br />
We can hidden columns in datatable like this one.
<pre><code>
$(document).ready(function() {
$('#datatables').DataTable( {
"columnDefs": [
{
"targets": [ 2 ],
"visible": false,
"searchable": false
}
]
} );
} );
</code>
</pre>
<code>"columnDefs"</code> : the keyword of its configuration, in the form object.
<code>"targets"</code>: Initialization of the order of columns to be hide, its form aray.
<code>"visible"</code> : visible in type data boolean. true or false
<code>"searchable"</code> : searchable in type data boolean. true or false
https://res.cloudinary.com/hpiynhbhq/image/upload/v1516725680/w5edp99vmr60snrekalf.png
we can see the column office not see again, it's because we hide aray into 2 of the columns ie office columns, because in array form, we start the sequence of numbers from 0.
We have successfully used datatable jquery on our web, there are many configurations and other customization from datatables.net, I will discuss in the next tutorial. so many of me hopefully this tutorial can be useful for you. thank you
<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@alfarisi94/how-to-use-datatables-in-our-web">Utopian.io - Rewarding Open Source Contributors</a></em><hr/>