Hi,
I'm now able to perform CRUD operations. However, I'm unable to display the data and perform CRUD operations with dropdown fields.
I'm only seeing a blank page with "Machine Management" heading once I changed two fields type from "text" to "select". If I set the fields type to "text" back and remove other dropdown properties, everything is working perfectly.
The following is the flow:
Here is the code:
[{"id":"2cebe15.5254a1e","type":"http in","z":"3f384dee.a0ca22","name":"","url":"/app","method":"get","upload":false,"swaggerDoc":"","x":105,"y":60,"wires":[["127b16b9.f62b19"]]},{"id":"127b16b9.f62b19","type":"function","z":"3f384dee.a0ca22","name":"select-query","func":"//var msg1={};\n//msg.topic=\"SELECT id AS mac_id, name AS mac_name FROM machine_type\";\n//msg1.topic=\"SELECT id AS loc_id, location AS loc_name FROM location\";\nif (msg.payload.name===\"\" && msg.payload.description===\"\" && msg.payload.location===\"\" && msg.payload.type===\"\" && msg.payload.ip_address===\"\" && msg.payload.ip_port===\"\" && msg.payload.process_code===\"\")\n{\n msg.topic=\"SELECT machine2.id AS id, machine2.name AS name, machine2.description AS description, location.location AS location, machine_type.name AS type, users.name AS owner_id, machine2.ip_address AS ip_address, machine2.ip_port AS ip_port, machine2.process_code AS process_code, machine2.enabled AS enabled FROM machine2 INNER JOIN machine_type ON machine_type.id = machine2.type INNER JOIN location ON location.id = machine2.location INNER JOIN users ON users.id = machine2.owner_id ORDER BY machine2.id DESC\";\n}\nelse\n{\n msg.topic=\"SELECT machine2.id AS id, machine2.name AS name, machine2.description AS description, location.location AS location, machine_type.name AS type, users.name AS owner_id, machine2.ip_address AS ip_address, machine2.ip_port AS ip_port, machine2.process_code AS process_code, machine2.enabled AS enabled FROM machine2 INNER JOIN machine_type ON machine_type.id = machine2.type INNER JOIN location ON location.id = machine2.location INNER JOIN users ON users.id = machine2.owner_id WHERE machine2.name='\" + msg.payload.name + \"' OR machine2.description='\" + msg.payload.description + \"' OR location.id='\" + msg.payload.location + \"' OR machine_type.id='\" + msg.payload.type + \"' OR machine2.ip_address='\" + msg.payload.ip_address + \"' OR machine2.ip_port='\" + msg.payload.ip_port + \"' OR machine2.process_code='\" + msg.payload.process_code + \"' ORDER BY machine2.id DESC\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":325,"y":60,"wires":[["98180f70.264e2"]]},{"id":"bc7be8bb.430798","type":"json","z":"3f384dee.a0ca22","name":"","property":"payload","action":"","pretty":false,"x":650,"y":60,"wires":[["edc26dc.5f20e9"]]},{"id":"edc26dc.5f20e9","type":"template","z":"3f384dee.a0ca22","name":"web-template","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <title>Machine Management</title>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\">\n <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-timepicker/0.5.2/css/bootstrap-timepicker.min.css\" />\n <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js\"></script>\n <script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"></script>\n <link type=\"text/css\" rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css\" />\n <link type=\"text/css\" rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css\" />\n <script type=\"text/javascript\" src=\"https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js\"></script>\n <style>\n h1 { text-align: center }\n </style>\n <script type=\"text/javascript\">\n $(function() {\n var db = {{{payload}}};\n $(\"#jsgrid\").jsGrid({\n width: \"100%\",\n\n filtering: true,\n inserting: true,\n editing: true,\n sorting: true,\n paging: true,\n autoload: true,\n\n deleteConfirm: function(item) {\n return \"Machine \" + item.name + \" information will be deleted. Are you sure?\";\n },\n \n pageSize: 30,\n\n /*\n rowClick: function(args) {\n showDetailsDialog(\"Edit\", args.item);\n },\n */\n\n data: db,\n\n fields: [{\n type: \"control\"\n }, {\n title: \"Enabled\",\n name: \"enabled\",\n type: \"checkbox\",\n width: 60,\n filtering: false\n }, {\n title: \"ID\",\n name: \"id\",\n type: \"number\",\n filtering: false,\n inserting: false,\n editing: false,\n width: 50,\n align: \"left\"\n }, {\n title: \"Code\",\n name: \"name\",\n type: \"text\",\n width: 70\n }, {\n title: \"Description\",\n name: \"description\",\n type: \"text\"\n }, {\n title: \"Location\",\n name: \"location\",\n //type: \"text\",\n type: \"select\",\n items: db.location,\n valueField: \"id\",\n textField: \"location\",\n width: 75\n }, {\n title: \"Type\",\n name: \"type\",\n //type: \"text\",\n type: \"select\",\n items: db.machine_type,\n valueField: \"id\",\n textField: \"name\",\n width: 75\n }, {\n title: \"Owner\",\n name: \"owner_id\",\n type: \"text\",\n filtering: false,\n inserting: false,\n editing: false\n }, {\n title: \"IP Address\",\n name: \"ip_address\",\n type: \"text\",\n width: 70\n }, {\n title: \"IP Port\",\n name: \"ip_port\",\n type: \"text\",\n width: 50\n }, {\n title: \"Process Code\",\n name: \"process_code\",\n type: \"text\",\n width: 60\n }],\n\n controller: {\n loadData: function(filter) {\n return $.ajax({\n type: \"GET\",\n url: \"/search\",\n data: filter\n });\n },\n insertItem: function(item) {\n return $.ajax({\n type: \"POST\",\n url: \"/insert\",\n data: item\n });\n },\n updateItem: function(item) {\n return $.ajax({\n type: \"PUT\",\n url: \"/update\",\n data: item\n });\n },\n deleteItem: function(item) {\n return $.ajax({\n type: \"DELETE\",\n url: \"/delete\",\n data: item\n });\n }\n }\n });\n });\n </script>\n</head>\n\n<body class=\"container\">\n <section class=\"row\">\n <h1>Machine Management</h1>\n <div class=\"col-lg-12\"></div>\n <div class=\"col-lg-12\" id=\"jsgrid\">\n </div>\n </section>\n</body>\n</html>","x":830,"y":60,"wires":[["63708ec.2e7617"]]},{"id":"63708ec.2e7617","type":"http response","z":"3f384dee.a0ca22","name":"","statusCode":"","headers":{},"x":1010,"y":60,"wires":[]},{"id":"d81d4a4d.77f1c8","type":"http in","z":"3f384dee.a0ca22","name":"","url":"/update","method":"put","upload":false,"swaggerDoc":"","x":115,"y":210,"wires":[["70ecf663.6b2108"]]},{"id":"bd5710a6.0b1e5","type":"function","z":"3f384dee.a0ca22","name":"update-response","func":"msg.payload=msg.result;\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":210,"wires":[["dd875985.366d78"]]},{"id":"4fe0652c.1beb6c","type":"http in","z":"3f384dee.a0ca22","name":"","url":"/insert","method":"post","upload":false,"swaggerDoc":"","x":115,"y":135,"wires":[["4228be9a.47891"]]},{"id":"1d3429af.0d5b66","type":"http in","z":"3f384dee.a0ca22","name":"","url":"/delete","method":"delete","upload":false,"swaggerDoc":"","x":125,"y":285,"wires":[["88d03b1e.8f8408"]]},{"id":"102f6c93.a2f413","type":"function","z":"3f384dee.a0ca22","name":"insert-response","func":"msg.payload=msg.result;\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":135,"wires":[["e09d5fa1.472d"]]},{"id":"4228be9a.47891","type":"function","z":"3f384dee.a0ca22","name":"insert-query","func":"if (msg.payload.enabled===\"true\")\n{\n msg.topic=\"INSERT INTO machine2 (enabled,id,name,description,ip_address,ip_port,process_code) VALUES ('1','\" + msg.payload.name + \"','\" + msg.payload.description + \"','\" + msg.payload.ip_address + \"','\" + msg.payload.ip_port + \"','\" + msg.payload.process_code + \"')\";\n}\nelse\n{\n msg.topic=\"INSERT INTO machine2 (enabled,id,name,description,ip_address,ip_port,process_code) VALUES ('0','\" + msg.payload.name + \"','\" + msg.payload.description + \"','\" + msg.payload.ip_address + \"','\" + msg.payload.ip_port + \"','\" + msg.payload.process_code + \"')\"; \n}\nreturn msg;","outputs":1,"noerr":0,"x":325,"y":135,"wires":[["2cd887e8.423148"]]},{"id":"70ecf663.6b2108","type":"function","z":"3f384dee.a0ca22","name":"update-query","func":"if (msg.payload.enabled===\"true\")\n{\n msg.topic=\"UPDATE machine2 SET enabled='1', name='\" + msg.payload.name + \"', description='\" + msg.payload.description + \"', ip_address='\" + msg.payload.ip_address + \"', ip_port='\" + msg.payload.ip_port + \"', process_code='\" + msg.payload.process_code + \"' WHERE id='\" + msg.payload.id + \"'\";\n}\nelse\n{\n msg.topic=\"UPDATE machine2 SET enabled='0', name='\" + msg.payload.name + \"', description='\" + msg.payload.description + \"', ip_address='\" + msg.payload.ip_address + \"', ip_port='\" + msg.payload.ip_port + \"', process_code='\" + msg.payload.process_code + \"' WHERE id='\" + msg.payload.id + \"'\"; \n}\nreturn msg;","outputs":1,"noerr":0,"x":325,"y":210,"wires":[["65b8e1cd.c37d8"]]},{"id":"6aa64c7d.45aa44","type":"function","z":"3f384dee.a0ca22","name":"delete-response","func":"msg.payload=msg.result;\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":285,"wires":[["ea5e155b.decbc8"]]},{"id":"88d03b1e.8f8408","type":"function","z":"3f384dee.a0ca22","name":"delete-query","func":"msg.topic=\"DELETE FROM machine2 WHERE id='\" + msg.payload.id + \"'\";\nreturn msg;","outputs":1,"noerr":0,"x":325,"y":285,"wires":[["627bcf35.3281c"]]},{"id":"ea5e155b.decbc8","type":"http response","z":"3f384dee.a0ca22","name":"","x":1010,"y":285,"wires":[]},{"id":"dd875985.366d78","type":"http response","z":"3f384dee.a0ca22","name":"","x":1010,"y":210,"wires":[]},{"id":"e09d5fa1.472d","type":"http response","z":"3f384dee.a0ca22","name":"","x":1010,"y":135,"wires":[]},{"id":"160f4157.f6e32f","type":"http in","z":"3f384dee.a0ca22","name":"","url":"/search","method":"get","upload":false,"swaggerDoc":"","x":115,"y":360,"wires":[["8f7020f9.e1f22"]]},{"id":"8f7020f9.e1f22","type":"function","z":"3f384dee.a0ca22","name":"search-query","func":"if (msg.payload.name===\"\" && msg.payload.description===\"\" && msg.payload.location===\"\" && msg.payload.type===\"\" && msg.payload.ip_address===\"\" && msg.payload.ip_port===\"\" && msg.payload.process_code===\"\")\n{\n msg.topic=\"SELECT machine2.id AS id, machine2.name AS name, machine2.description AS description, location.location AS location, machine_type.name AS type, users.name AS owner_id, machine2.ip_address AS ip_address, machine2.ip_port AS ip_port, machine2.process_code AS process_code, machine2.enabled AS enabled FROM machine2 INNER JOIN machine_type ON machine_type.id = machine2.type INNER JOIN location ON location.id = machine2.location INNER JOIN users ON users.id = machine2.owner_id ORDER BY machine2.id DESC\";\n}\nelse\n{\n msg.topic=\"SELECT machine2.id AS id, machine2.name AS name, machine2.description AS description, location.location AS location, machine_type.name AS type, users.name AS owner_id, machine2.ip_address AS ip_address, machine2.ip_port AS ip_port, machine2.process_code AS process_code, machine2.enabled AS enabled FROM machine2 INNER JOIN machine_type ON machine_type.id = machine2.type INNER JOIN location ON location.id = machine2.location INNER JOIN users ON users.id = machine2.owner_id WHERE machine2.name='\" + msg.payload.name + \"' OR machine2.description='\" + msg.payload.description + \"' OR location.id='\" + msg.payload.location + \"' OR machine_type.id='\" + msg.payload.type + \"' OR machine2.ip_address='\" + msg.payload.ip_address + \"' OR machine2.ip_port='\" + msg.payload.ip_port + \"' OR machine2.process_code='\" + msg.payload.process_code + \"' ORDER BY machine2.id DESC\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":325,"y":360,"wires":[["2a6cfcbd.f00d84"]]},{"id":"1041cd5a.7d8463","type":"http response","z":"3f384dee.a0ca22","name":"","statusCode":"","headers":{},"x":1010,"y":360,"wires":[]},{"id":"577755ce.4f4b6c","type":"function","z":"3f384dee.a0ca22","name":"search-response","func":"return msg;","outputs":1,"noerr":0,"x":690,"y":360,"wires":[["1041cd5a.7d8463"]]},{"id":"36e8e622.a1946a","type":"debug","z":"3f384dee.a0ca22","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":670,"y":435,"wires":[]},{"id":"98180f70.264e2","type":"mysql","z":"3f384dee.a0ca22","mydb":"8429c6f1.4909c8","name":"database","x":495,"y":60,"wires":[["bc7be8bb.430798"]]},{"id":"65b8e1cd.c37d8","type":"mysql","z":"3f384dee.a0ca22","mydb":"8429c6f1.4909c8","name":"database","x":495,"y":210,"wires":[["bd5710a6.0b1e5"]]},{"id":"2a6cfcbd.f00d84","type":"mysql","z":"3f384dee.a0ca22","mydb":"8429c6f1.4909c8","name":"database","x":495,"y":360,"wires":[["36e8e622.a1946a","577755ce.4f4b6c"]]},{"id":"627bcf35.3281c","type":"mysql","z":"3f384dee.a0ca22","mydb":"8429c6f1.4909c8","name":"database","x":495,"y":285,"wires":[["6aa64c7d.45aa44"]]},{"id":"2cd887e8.423148","type":"mysql","z":"3f384dee.a0ca22","mydb":"8429c6f1.4909c8","name":"database","x":495,"y":135,"wires":[["102f6c93.a2f413"]]},{"id":"8429c6f1.4909c8","type":"MySQLdatabase","z":"","host":"10.21.11.15","port":"3306","db":"i4inari","tz":""}]
Thanks for helping.