Guest User

Untitled

a guest
Apr 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. var editor; // use a global for the submit and return data rendering in the examples
  2.  
  3. $(document).ready(function() {
  4. editor = new $.fn.dataTable.Editor( {
  5. "ajax": "../php/staff.php",
  6. "table": "#example",
  7. "fields": [ {
  8. "label": "First name:",
  9. "name": "first_name"
  10. }, {
  11. "label": "Last name:",
  12. "name": "last_name"
  13. }, {
  14. "label": "Position:",
  15. "name": "position"
  16. }, {
  17. "label": "Office:",
  18. "name": "office"
  19. }, {
  20. "label": "Extension:",
  21. "name": "extn"
  22. }, {
  23. "label": "Start date:",
  24. "name": "start_date",
  25. "type": "datetime"
  26. }, {
  27. "label": "Salary:",
  28. "name": "salary"
  29. }
  30. ]
  31. } );
  32.  
  33. // New record
  34. $('a.editor_create').on('click', function (e) {
  35. e.preventDefault();
  36.  
  37. editor.create( {
  38. title: 'Create new record',
  39. buttons: 'Add'
  40. } );
  41. } );
  42.  
  43. // Edit record
  44. $('#example').on('click', 'a.editor_edit', function (e) {
  45. e.preventDefault();
  46.  
  47. editor.edit( $(this).closest('tr'), {
  48. title: 'Edit record',
  49. buttons: 'Update'
  50. } );
  51. } );
  52.  
  53. // Delete a record
  54. $('#example').on('click', 'a.editor_remove', function (e) {
  55. e.preventDefault();
  56.  
  57. editor.remove( $(this).closest('tr'), {
  58. title: 'Delete record',
  59. message: 'Are you sure you wish to remove this record?',
  60. buttons: 'Delete'
  61. } );
  62. } );
  63.  
  64. $('#example').DataTable( {
  65. ajax: "../php/staff.php",
  66. columns: [
  67. { data: null, render: function ( data, type, row ) {
  68. // Combine the first and last names into a single table field
  69. return data.first_name+' '+data.last_name;
  70. } },
  71. { data: "position" },
  72. { data: "office" },
  73. { data: "extn" },
  74. { data: "start_date" },
  75. { data: "salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) },
  76. {
  77. data: null,
  78. className: "center",
  79. defaultContent: '<a href="" class="editor_edit">Edit</a> / <a href="" class="editor_remove">Delete</a>'
  80. }
  81. ]
  82. } );
  83. } );
Add Comment
Please, Sign In to add comment