Advertisement
rhuntington

Working JS Grid Script

Mar 11th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let roomChange;
  2.  
  3. let actions = [
  4.     { "Action": "Set" },
  5.     { "Action": "Mod" },
  6.     { "Action": "Strike" },
  7.     { "Action": "Carry" }
  8. ];
  9.  
  10. let rooms = [
  11.     { "Room": "Empire", id: 0 },
  12.     { "Room": "Empire A", id: 1 },
  13.     { "Room": "Empire B", id: 2 },
  14.     { "Room": "Empire C", id: 3 },
  15.  
  16. ];
  17.  
  18. $("#jsgrid").jsGrid({
  19.     width: "100%",
  20.     height: "400px",
  21.  
  22.     inserting: true,
  23.     editing: true,
  24.     sorting: true,
  25.     paging: true,
  26.  
  27.     // data: clients,
  28.  
  29.     fields: [
  30.         {
  31.             name: "Room", type: "select", items: rooms, textField: "Room", valueField: "id", validate: "required"
  32.         },
  33.         { name: "Action", type: "select", items: actions, textField: "Action", valueField: "Action" },
  34.         { name: "Note", type: "text" },
  35.         { name: "Day", type: "date" },
  36.         { type: "control" }
  37.     ],
  38.     controller: {
  39.         insertItem: (item) => {
  40.             if (item.Note == "") {
  41.                 item.Note = "-";
  42.             }
  43.             if (item.Action == "Mod") {
  44.                 // if action = mod, get extra input and set the roomChange var to value of what user selects
  45.                 $("#exampleModal").modal();
  46.                 /* NO ACTUAL FUNCTIONALITY! JUST PROOF OF CONCEPT */
  47.                 roomChange = 1; // Set var to user's val
  48.             } else {
  49.                 // If not mod, then set/reset var to what user has selected in the table
  50.                 roomChange = item.Room;
  51.             }
  52.         },
  53.  
  54.     }
  55. });
  56.  
  57. /* Event listener for insert button click */
  58. $(document).on('click', '.jsgrid-insert-button', () => {
  59.     $("select").val(roomChange); // updates select value based on user's input
  60. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement