rows-reordering.html 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5. <title>jsGrid - Rows Reordering Scenario</title>
  6. <link rel="stylesheet" type="text/css" href="demos.css" />
  7. <link href='http://fonts.googleapis.com/css?family=Open+Sans:300,600,400' rel='stylesheet' type='text/css'>
  8. <link rel="stylesheet" type="text/css" href="../css/jsgrid.css" />
  9. <link rel="stylesheet" type="text/css" href="../css/theme.css" />
  10. <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/cupertino/jquery-ui.css">
  11. <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  12. <script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
  13. <script src="db.js"></script>
  14. <script src="../src/jsgrid.core.js"></script>
  15. <script src="../src/jsgrid.load-indicator.js"></script>
  16. <script src="../src/jsgrid.load-strategies.js"></script>
  17. <script src="../src/jsgrid.sort-strategies.js"></script>
  18. <script src="../src/jsgrid.field.js"></script>
  19. <script src="../src/fields/jsgrid.field.text.js"></script>
  20. <script src="../src/fields/jsgrid.field.number.js"></script>
  21. <script src="../src/fields/jsgrid.field.select.js"></script>
  22. <script src="../src/fields/jsgrid.field.checkbox.js"></script>
  23. <script src="../src/fields/jsgrid.field.control.js"></script>
  24. </head>
  25. <body>
  26. <h1>Rows Reordering Scenario</h1>
  27. <div id="jsGrid"></div>
  28. <script>
  29. $(function() {
  30. $("#jsGrid").jsGrid({
  31. height: "70%",
  32. width: "100%",
  33. autoload: true,
  34. rowClass: function(item, itemIndex) {
  35. return "client-" + itemIndex;
  36. },
  37. controller: {
  38. loadData: function() {
  39. return db.clients.slice(0, 15);
  40. }
  41. },
  42. fields: [
  43. { name: "Name", type: "text", width: 150 },
  44. { name: "Age", type: "number", width: 50 },
  45. { name: "Address", type: "text", width: 200 },
  46. { name: "Country", type: "select", items: db.countries, valueField: "Id", textField: "Name" },
  47. { name: "Married", type: "checkbox", title: "Is Married", sorting: false }
  48. ],
  49. onRefreshed: function() {
  50. var $gridData = $("#jsGrid .jsgrid-grid-body tbody");
  51. $gridData.sortable({
  52. update: function(e, ui) {
  53. // array of indexes
  54. var clientIndexRegExp = /\s*client-(\d+)\s*/;
  55. var indexes = $.map($gridData.sortable("toArray", { attribute: "class" }), function(classes) {
  56. return clientIndexRegExp.exec(classes)[1];
  57. });
  58. alert("Reordered indexes: " + indexes.join(", "));
  59. // arrays of items
  60. var items = $.map($gridData.find("tr"), function(row) {
  61. return $(row).data("JSGridItem");
  62. });
  63. console && console.log("Reordered items", items);
  64. }
  65. });
  66. }
  67. });
  68. });
  69. </script>
  70. </body>
  71. </html>