项目作者: OxiGen1001

项目描述 :
Manipulation of table (sort, add, edit, remove, etc... - rows | valid cells, type, require, etc... cells )
高级语言: JavaScript
项目地址: git://github.com/OxiGen1001/ediTable.git
创建时间: 2019-04-02T05:03:30Z
项目社区:https://github.com/OxiGen1001/ediTable

开源协议:MIT License

下载


ediTable v0.0.3 (beta) Jquery Plugin

ediTable is a JQuery plugin that lets you create table via json,make it sortable, also editable so you can manipulate any cell, set type of input for every cell (text, number, color, select, image, checkbox…) validate cells, make them required etc… add buttons edit/delete/custom buttons…

Demo:

Features overview

  • Works with any Design Framework (bootstrap,material,materializecss…).
  • Creation via (html/json/mix).
  • Editable/Sortable table.
  • Type of columns (text, number, color, select, image, checkbox…).
  • Validation of inputs columns + Require.
  • Function Before/After Actions ( for Mask plugins,Design etc…)

    Log:

  • v0.0.3
    1. get data of table.
    2. save/delete via AJAX.
    3. fix some bugs
  • v0.0.2:
    1. add new property unchecked.
    2. checkbox accepts boolean/string/numbers.

Installation

Include css file if you’re interested by it (not required) in your HTML code.

  1. <link rel="stylesheet" href="/dist/ediTable.min.css" type="text/css" />

Include Libs in your HTML code:

  1. <script src="/lib/jquery.js"></script>
  2. <script src="/dist/ediTable.min.js"></script>

Usage

  • Creating table via JSON :

    1. <table>
    2. </table>
    3. <script>
    4. $("table").ediTable({
    5. json:
    6. {
    7. body:jsonArray,
    8. },
    9. });
    10. </script>
  • Creating table via HTML

    1. <table>
    2. <thead>
    3. <tr>
    4. <th>ID</th>
    5. <th>Name</th>
    6. </tr>
    7. </thead>
    8. <body>
    9. <tr>
    10. <td data-index="id">1</td>
    11. <td data-index="name">Med</td>
    12. </tr>
    13. </body>
    14. </table>
    15. <script>
    16. $("table").ediTable();
    17. </script>
  • Creating table via (HTML/JSON)

    1. <table>
    2. <thead>
    3. <tr>
    4. <th>ID</th>
    5. <th>Name</th>
    6. </tr>
    7. </thead>
    8. <body>
    9. <tr>
    10. <td data-index="id">1</td>
    11. <td data-index="name">Med</td>
    12. </tr>
    13. </body>
    14. </table>
    15. <script>
    16. $("table").ediTable({
    17. json:
    18. {
    19. body:jsonArray,
    20. },
    21. });
    22. </script>

    Options

    |Name|Type| Default |Description|
    |—|—|—| —|
    | editable | boolean | true | make table editable |
    | sortable | boolean | false | make table sortable |
    | json | Object | ——— | create and define columns (type, title) |
    | button | Object | ——— | add edit, delete & custom buttons |
    | add | boolean | false | add new row |
    | keyboard| bool | true | allow Esc/Enter canceling/saving row|
    | beforeSave | Function| ——— | before switching to save mode |
    | afterSave | Function| ——— | after switching to save mode |
    | beforeEdit| Function| ——— | before switching to edit mode |
    | afterEdit| Function| ——— | after switching to edit mode |
    | beforeDelete| Function| ——— | before switching to delete mode |
    | afterDelete | Function| ——— | after switching to delete mode|
    | requiredAction | Function| ——— | action on required error|
    | invalidAction | Function| ——— | action on invalid error|

Note:

  • double click if you wanna edit row.
  • click on the last row to add new one ( set add:true )

    Extra Information

    JSON object

    json option has 2 arrays, head & body:
  1. head is empty array by default and its role is defining columns:

    1. -E.G:
    2. //...
    3. json:{
    4. head:
    5. [
    6. {
    7. title:"Column 1", // TH tag(string), default is name property
    8. type:"number", // default text
    9. validation:false, //default true,
    10. required:false, //default true
    11. min:-5, // works with only (number)
    12. max:5, // works with only (number)
    13. editable:false //default true
    14. },
    15. {
    16. title:"Column 2",
    17. type:"checkbox",
    18. checked:"x", // all cells with x value will be checked // required property
    19. unchecked:"y",
    20. label:function($value){ // $value return value1 (x) or value2
    21. if($value==something)
    22. return "label1" // e.g : "Active"/"paid"...
    23. return "label2" // e.g : "Unactive"/"unpaid"...
    24. },
    25. editable:true,
    26. },
    27. {
    28. type:"select",
    29. data: // required property
    30. [
    31. {
    32. value:0,
    33. label:"male"
    34. },
    35. {
    36. value:1,
    37. label:"female"
    38. }
    39. ],
    40. },
    41. {
    42. title:"Pic profil",
    43. type:"image", // non-editable
    44. },
    45. ]
    46. }

    Note: if you don’t wanna define some column, you need to set it ,{},

    1. //...
    2. {
    3. title:"X",
    4. type:"type1"
    5. },
    6. {}, // if you don't wanna define this column.
    7. {
    8. title:"Y",
    9. type:"type2"
    10. },
  2. body is empty array by default and its where you set your data (JSON data):
    e.g:

    1. json:{
    2. body:
    3. [
    4. //...
    5. {
    6. id:70,
    7. name:"Med",
    8. birthday:"1789-01-04",
    9. //...
    10. }
    11. //...
    12. ]
    13. }

    Button object

    Button is object where you can set your custom buttons or active edit/delete buttons, it has 2 objects, edit & delete button with default values :

  3. edit/delete objects:

    1. -E.G:
    2. //...
    3. button:
    4. {
    5. edit:
    6. {
    7. active:true, // default: false
    8. text:"<i class="far fa-edit"></i>", // default: edit (text when row in show mode)
    9. textActive:"<i class="far fa-save"></i>", // default: edit (text when row in edit mode)
    10. selector:"editButton", // class, default: edit
    11. },
    12. delete:
    13. {
    14. active:true, // default: false //required property
    15. text:"<i class="fas fa-trash-alt"></i>", // default: delete
    16. selector:"deleteButton", // class, default: delete
    17. },
    18. title:"Custom Title" // TH of column default : Actions
    19. }
    20. //...
  4. creating custom button:
  1. //...
  2. customButton1:
  3. {
  4. active:true,
  5. text:"whatever",
  6. //textActive:"", // you can use it if you wanna change button's text in the edit mode.
  7. selector:"customButtonSelector",
  8. action:function(values,tr) // action on click.
  9. {
  10. // some logic
  11. }
  12. }
  13. //...

Save

  1. Save via Ajax (by row) using jquery function $.ajax

    1. //...
    2. afterSave:function(values,oldvalues){
    3. formdata=new FormData();
    4. $.each(values,function(index,cellValue){
    5. formdata.append(index,cellValue);
    6. });
    7. $.ajax({
    8. url:"/path/serverFile[.extension]",
    9. data:formdata,
    10. type:"method",
    11. success:function(resp){}
    12. });
    13. },
  2. Delete via Ajax (by row) using jquery function $.ajax

    1. //..
    2. afterDelete:function(values)
    3. {
    4. $.ajax({
    5. url:"/path/serverFile[.extension]",
    6. data:{id:values._id},
    7. success:function(resp){}
    8. });
    9. }
    10. //...
  3. Get the table data

    • ediTable library applied on a single table :

      1. <table id="table1"></table>
      2. <table id="table2"></table>
      3. <table id="table3"></table>
      4. var table=$("#table1").ediTable({[...]});
      5. table.data();
    • ediTable library applied on multi tables :

      1. <table id="table1"></table>
      2. <table id="table2"></table>
      3. <table id="table3"></table>
      4. var table=$("table").ediTable({[...]});
      5. index = 0; // 0 => first table | 1 => second table | ...
      6. table.data(index); //index of table 0,1,2...

      Columns Types

      Types of columns inputs.

Name/Properties validation editable required title data label min max checked unchecked
text
checkbox
number
image
select
url
color
email

Methods Arguments

  1. beforeSave:function(values,$tr){},
  2. afterSave:function(newValues,oldValues,$tr){},
  3. beforeEdit:function(values,$tr){},
  4. afterEdit:function(values,$tr){},
  5. beforeDelete:function(values,$tr){},
  6. afterDelete:function(values,$tr){},

Contact

  • any bug/issue you fall in you can report it.
  • any suggest contact me.