Create a Custom Grid in PHP With Datatable

Hi Guys,

In PHP, you can create a custom grid using Datatable.
If you want to create a custom grid using Datatable, you can use the following code snippet:

// Add HTML Code

<table class="table" id="tableTestId" cellpadding="5" cellspacing="5" width="100%">
<th align="center">ID</th>
<th align="center">Column1</th>
<th align="center">Column2</th>
<?php foreach ($phpResults as $result) { ?>
<td align="center"><?php echo $result["id"]; ?></td>
<td style='text-align:center'><?php echo $result['column1'] ?></td>
<td style='text-align:center'><?php echo $result['column2']; ?></td>
<?php } ?>

/******Add jQuery Code for Data tables**********/
Add below scripts to you code to work with Datatables:

After adding the above links, use the following:

$(document).ready(function() {

That’s it you are done!


Leave a Reply