This tutorial help to understand Bootgrid listing with PHP, MySQL Using Ajax.We will convert a simple HTML table into a feature table with features such as table data searching, pagination, column sorting, and many more.
Bootgrid is a fantastic grid plugin for displaying results. Bootgrid grid is a bootstrap-specific grid control. Bootgrid Lightweight, Cross Browser Support (IE, Firefox, Chrome, Safari, Opera), and HTML5 support are among its many features.
You can use bootgrid to generate a listing using two methods.
You can also check other tutorial for Grid,
Bootgrid is an extremely well-built jQuery grid plugin that is used to transform a simple HTML table into a powerful grid with functionality such as inserting, updating, and deleting records from the table, table column sorting, pagination, and searching data on the server side.
Client-side means you offer pagination, sorting, and searching by loading entire data sets at once. This will work fine for a small set of records, but if you have a large set of records, you will run into performance issues because fetching large amounts of data from the server side will take time to process and load data into the table.
There is no special configuration required to use bootgrid on a table. You must retrieve all records from the database and bind them to the table using rows
via HTML
or use the jQuery append method to dynamically append rows to the table body. Finally, use the data-toggle="bootgrid"
attribute in your table to initialize bootgrid, as shown below.
<table id="employee_grid" class="table table-condensed table-hover table-striped" width="100%" cellspacing="0" data-toggle="bootgrid"> ... </table>
data-toggle
use to initialize bootgrid on the table.
Server-side processing will come into the picture when you have a large set of data. Server side data will fetch data in chunk, so data overhead of your application will improve and get better performance of application. We need the ajax option to true and pass an URL to the url option in the bootgrid method.
index.php.
Step 1: Include js and css file into index.php.
<script src="dist/jquery-1.11.1.min.js"></script> <script src="dist/bootstrap.min.js"></script> <script src="dist/jquery.bootgrid.min.js"></script>
Step 2: Define html table and call data-toggle="bootgrid"
attribute
<table id="employee_grid" class="table table-condensed table-hover table-striped" width="100%" cellspacing="0" data-toggle="bootgrid"> <thead> <tr> <th data-column-id="id" data-type="numeric">Empid</th> <th data-column-id="employee_name">Name</th> <th data-column-id="employee_salary">Salary</th> <th data-column-id="employee_age">Age</th> </tr> </thead> </table>
Step 3: Define ajax request
to fetch data from server-side.
$("#employee_grid").bootgrid({ ajax: true, post: function () { /* To accumulate custom parameter with the request object */ return { id: "b0df282a-0d67-40e5-8558-c9e93b7befed" }; }, url: "response.php", formatters: { } });
Here #employee_grid
is table id where i am implementing bootgrid and url: "response.php"
is the target service or file to call on each pagination request.
Step 4: response.php
will contain all server-side processing logic and code.
$totalRecords = mysqli_num_rows($queryTot); $queryRecords = mysqli_query($conn, $sqlRec) or die("error to fetch employees data"); //iterate on results row and create new index array of data while( $row = mysqli_fetch_assoc($queryRecords) ) { $data[] = $row; } $json_data = array( "current" => intval( $params['current'] ), "rowCount" => 10, "total" => intval( $totalRecords ), "rows" => $data // total data array ); echo json_encode($json_data); // send data as json format
Bootgrid is very simple and easy to use with php and MySQL.We can use one-time data records(Client side sorting, searching and pagination) as well as server-side (sorting, searching and pagination) for large data sets.
Please feel free to send queries to me using below comment section.
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More
View Comments
I want to thanks to samuel, who made some changes for laravel Framework,
//Handles Sort query string sent from Bootgrid
if (isset($params['sort']) && is_array($params['sort']) )
{
$order_by="";
foreach($params['sort'] as $key=> $value)
$order_by.=" $key $value";
$where .="ORDER BY ".$order_by." ";
}
I implemented it in one of my project, the search is not functioning.
I have cross verified on my tuts and demo,it should be work.
I checked in demo link,its working fine bro
me try this then comment
Which issues are you facing,I haven't get any comment from your side regrading this on this post.
This article is very helpful, I really appreciate.
but how to put the Edit and Delete button and enter the KEY ID on each line for the next action ?
Please explain to me and give some examples.
Thank You.
You can add/edit/delete button like datatable example,anyways i will share new article with this requirement.
I've followed the above tutorial and also the below JQuery Bootgrid documentation in order to create a dataGrid for my DB.
- http://www.abrandao.com/2014/11/bootstrap-bootgrid-with-php-pdo-server-script/
- http://www.jquery-bootgrid.com/Documentation#column
Unfortunately, I'm not able to display the Command buttons on the code below, when trying to display them using "formatters":
Here is my question submitted on
stackoverflow.com
http://stackoverflow.com/questions/39321000/jquery-bootgrid-not-displaying-command-buttons
Any help would be really appreciated.
Thank you....
i am using below bootgrid config code,Its working fine.
$( document ).ready(function() {
var grid = $("#employee_grid").bootgrid({
ajax: true,
post: function ()
{
/* To accumulate custom parameter with the request object */
return {
id: "b0df282a-0d67-40e5-8558-c9e93b7befed"
};
},
url: "response.php",
formatters: {
"commands": function(column, row)
{
return " " +
"";
}
}
}).on("loaded.rs.jquery.bootgrid", function()
{
/* Executes after data is loaded and rendered */
grid.find(".command-edit").on("click", function(e)
{
alert("You pressed edit on row: " + $(this).data("row-id"));
}).end().find(".command-delete").on("click", function(e)
{
alert("You pressed delete on row: " + $(this).data("row-id"));
});
});
});
i am using bootstrap icon classes
Hello Dear, you were right.... I had another object with the same name as my command column, hence it won't display command columns..
Thank you so much for your quick answer.
i have share full source code, you need to create test folder, dump mysql file in test db.You need put source code into xampp like, xampp/htdocs/bootgrid, now open localhost/bootgrid, it will work perfectly.
here delete function not working
uncomment below code into index.php,
$.post('response.php', { id: $(this).data("row-id"), action:'delete'}
, function(){
// when ajax returns (callback),
$("#employee_grid").bootgrid('reload');
});
need to see code
Hi,
I had this working fine on php mysql, but now I have to migrate this code to be able to run on sql server, I managed do all the php stuff but I am stuck with the response.php code converting from mysql to sql server, do you have any conversion done?
sorry, I do not have