项目作者: samweru

项目描述 :
jQuery DataGrid
高级语言: JavaScript
项目地址: git://github.com/samweru/simplr-grid.git
创建时间: 2016-09-04T00:31:50Z
项目社区:https://github.com/samweru/simplr-grid

开源协议:MIT License

下载


Simplr Grid

simplr-grid

Usage

  1. var button = $(document.createElement("BUTTON"));
  2. var customToolbar = [
  3. button.clone().html("Add").click(function(){
  4. console.log("Button Add Clicked.")
  5. }),
  6. button.clone().html("Sel").click(function(){
  7. console.log("Button Select Clicked.")
  8. })
  9. ];
  10. $("#employee-tbl").simplrGrid({
  11. title:"Employees",
  12. url:"/data/employees",
  13. method:"POST",
  14. singleSelect:true,
  15. usePager:true,
  16. fixHeader:true,
  17. fixLeftColumn:true,
  18. resizeColumns:true,
  19. // data:[] //if you want to input data directly. Overrides Ajax
  20. columns:{
  21. "id":{name:"#", css:{display:"none"}},
  22. "email":{name:"Email", css:{textDecoration:"underline"}},
  23. "county":{name:"County"},
  24. "mobile":{name:"Mobile"},
  25. "address":{name:"Address"},
  26. "married":{name:"Married"},
  27. "employed":{name:"Employed", css:{textAlign:"right", paddingRight:"10px"}},
  28. "lastname":{name:"Last Name"},
  29. "firstname":{name:"First Name"}
  30. },
  31. css:{
  32. gridWidth:"1100px",
  33. gridHeight:"400px",
  34. capsuleWidth:"100%",
  35. capsuleHeight:"600px",
  36. },
  37. toolbars:[
  38. customToolbar //This represents a single toolbar
  39. ],
  40. pager:{
  41. page:1,
  42. rows:10,
  43. list:[10,20,30,40,50]
  44. },
  45. dblClick:function(){
  46. console.log($(this).getRow());
  47. }
  48. })

Plugins

simplr-grid - is a plugin by itself but also includes other plugins that are already used in grid functionality. If you so wish to use them individually on other elements, you can:

  1. resizeColumns - use header to resize columns
  2. fixHeader - freeze header row
  3. fixLeftColumn - freeze left most column
  4. getSelectedRow & getSelectedRows - uses class .selected to get row(s)
  5. getRow - gets row data

Custom Ajax Setup

In case you want to use your own ajax function you can add customLoader as an option on simplr-grid this is useful when you want to mock

  1. customLoader:function(table, options, builder){
  2. $.ajax({
  3. type:options.method,
  4. dataType:'json',
  5. url:options.url,
  6. data:{
  7. page:options.pager.page,
  8. rows:options.pager.rows
  9. }
  10. })
  11. .done(function(response){
  12. //total-number-of-rows/rows-per-page
  13. options.pager.pages = Math.ceil(response.count/options.pager.rows);
  14. builder(table, response, options);
  15. })
  16. }

Need to know stuff

If you ever need to refresh the grid programmatically:

  1. $("#employee-tbl").trigger("refresh")

Refresh trigger also takes arguments for options as json ofcourse.

  1. $("#employee-tbl").trigger("refresh", options)

Contributions

Thanks a lot to the developer(s) of the plugin(s) below:

TableHeadFixer

Some goodies used in this project.

Have fun!