Introducting
Open JS Grid v2

<?php | |
require_once("grid.php"); | |
$grid = new Grid("users", array( | |
"save"=>true, | |
"delete"=>true | |
)); | |
?> |
Open JS Grid comes with a mysql class so you don't have to do any database work yourself. Checkout the examples below on how to do what normally would be complex database queries.
Basic grid functionality here, you can sort columns, filter existing data, and resize the columns. You can also resize the grid. Along with that, if you resize the grid down small enough, it adjusts to fit small sizes.
Now you can make your own cell types for money, buttons, whatever alteration to data you want.
Turn on editing to edit cells. They can be text boxes, checkboxes, or even drop downs. Drop downs can even use data from other database tables.
You can do complex mysql things like where, join, concat, group, having and more. Its all completely customizable in your ajax php file.
The pager is smart. It can page through one at a time, page via a slider, or even type in the page you want. Searching is also smart. When you type, it live searches the current data. When you hit enter, it will search that query on the database.
All the CSS for the grid is written with Styuls. It's awesome.
I wrote this pluging to teach, not just provide a plugin. So please go into the code, tear it apart, read through it, play with it. There was a lot to learn here, so I hope you will learn something too.
Open JS Grid 2 is now completely OOP. Written against a really cool (soon to be release) library called RootJS.
Everybody seems to love twitter bootstrap for generic styles. So Open JS Grid includes and integrates with all those standard classes.
Instead of having built in callbacks, we have events that fire on the jQuery object. So you can bind to as many grid events as much and whenever you want.
This time around, the grid is built with Columns instead of rows. That makes for much much faster use in most cases.
<?php | |
require_once("grid.php"); | |
$grid = new Grid("users", array( | |
"delete"=>true | |
)); | |
?> |
<?php | |
require_once("grid.php"); | |
$grid = new Grid("users", array( | |
"save"=>true | |
)); | |
?> |
<table class="grid demo5" action="ajax.php"> | |
<tr> | |
<th col="Price" type="money">Price</th> | |
<th col="TutorialID" type="hashBang">TutorialID</th> | |
</tr> | |
</table> |
<?php | |
// require our class | |
require_once("grid.php"); | |
// load our grid with a table | |
$grid = new Grid("tutorials", array( | |
"save"=>true, | |
"select" => 'selectFunction' | |
)); | |
// if you have anonymous function support in PHP (5.3.2+) Then you can just write the | |
// Function above instead of creating a separate one here. | |
function selectFunction($grid) { | |
$selects = array(); | |
// category select | |
$grid->table = "categories"; | |
$selects["CategoryID"] = $grid->makeSelect("CategoryID","Name"); | |
// active select | |
$selects["active"] = array("1"=>"true","0"=>"false"); | |
// render data | |
$grid->render($selects); | |
} | |
?> |
<table class="grid demo5" action="ajax.php"> | |
<tr> | |
<th col="Price" type="money">Price</th> | |
<th col="TutorialID" type="hashBang">TutorialID</th> | |
</tr> | |
</table> |
var $grid = $(".demo6").grid({ | |
rowNumbers: true, | |
checkboxes:true | |
}); | |
$grid.on("rowCheck",function(e, $checkbox, rowData) { | |
// using the checkbox, seeing if were checked or unchecked | |
var checked = $checkbox[0].checked ? "checked" : "unchecked"; | |
// calling the notify method on the grid plugin | |
$(this).grid("notify","you "+checked+" "+rowData.Username,1000); | |
}); |
<script> | |
$(function(){ | |
var $grid = $(".demo6").grid({ | |
editing: true | |
}).on("loadComplete",function(e) { | |
// the add column | |
$(this).grid("addColumn","Add",{ | |
width: 60, | |
insertAt: "end", // index | column | "end" | "start" | |
header : "Action", | |
cellClass : "center" | |
}, function(i) { | |
return "<button class='btn btn-warning btn-mini'>Add</button>"; | |
}); | |
}); | |
// button click | |
$grid.on("click",".cell[data-col='Add'] button",function() { | |
var diag = $grid.grid("confirm","Are you sure you want to add?",function() { | |
$grid.grid("notify","fake add",1000); | |
console.log("diag",diag); | |
}); | |
}); | |
}); | |
</script> |
$grid->render($selects)
Where $selects is your assoc array of name/value pairs.