简体   繁体   English

Dojo-输入字段未追加到网格

[英]Dojo - Input fields are not Appending to the grid

I Created a grid using dojo.I 'm having a form with input fields while i entered the values and click the "Add Row" button the input fields are not appending to the grid. 我使用dojo创建了一个网格。我在输入值的同时拥有一个带有输入字段的表单,然后单击“添加行”按钮,输入字段未追加到网格。 Delete Option is working fine but add row is not working. 删除选项工作正常,但添加行不起作用。 I have attached the link of jsfiddle kindly refer for more. 我已附上jsfiddle的链接,以了解更多信息。

form = new Form({
    onSubmit: function(evt) {
        evt.preventDefault();
        var formValue = this.get("value");
        dataStore.newItem(formValue);
    }
}, "formContainer");
form.startup();
});

jsfiddle jsfiddle

There are some problems with your HTML code. 您的HTML代码有一些问题。 There is no need for the form element. 不需要form元素。 You just need a div and place your dijit.form.Form in the div element. 您只需要一个div并将dijit.form.Form放在div元素中。 And, the submit button needs to be inside that div . 并且, submit按钮必须位于该div It will automatically get triggered. 它会自动被触发。

See the updated fiddle: JSFiddle 请参阅更新的小提琴: JSFiddle

There is one more thing, to add data to the store, you have to provide an id to the newItem . 还有一件事,要将数据添加到存储中,您必须为newItem提供一个ID。 Store will not accept an element without an id. 商店将不接受没有ID的元素。

Fully agree with @Himanshu. 完全同意@Himanshu。
You HTML is strange. 您的HTML很奇怪。
If you want to use a submit button, you must put it inside the <form> element. 如果要使用submit按钮,则必须将其放在<form>元素内。

Also, still like @Himanshu said, you must provide an id in order to user newItem 另外,仍然像@Himanshu所说的那样,您必须提供一个id才能使用newItem
See the following working jsfiddle example: https://jsfiddle.net/xzkc7hbs/8/ 请参阅下面的工作jsfiddle示例: https ://jsfiddle.net/xzkc7hbs/8/

For better records, here is a working snippets. 为了获得更好的记录,以下是工作片段。 (ignore the script error, those are security warnings, and run it in full page. Otherwise the script errors are over the textboxes) (忽略脚本错误,这些是安全警告,并在整页中运行它。否则,脚本错误将超出文本框)

 require([ 'dojo/_base/lang', 'dojox/grid/DataGrid', 'dojo/data/ItemFileWriteStore', 'dojo/dom', 'dijit/form/Button', 'dojo/dom-class', "dojo/dom-construct", "dojo/on", "dijit/form/Form", "dijit/form/TextBox", "dojo/store/Memory", "dojo/data/ObjectStore", "dojo/request", "dijit/registry", 'dojo/domReady!', 'dojox/grid/_CheckBoxSelector' ], function(lang, DataGrid, ItemFileWriteStore, dom, Button, domClass, domConstruct, on, Form, TextBox, Memory, ObjectStore, request, registry) { var data = { identifier: 'id', items: [] }; var data_list = [{ fname: "Boy", lname: "Mayer", email: "boy@mayer.com", num: 54526 }, { fname: "Paul", lname: "Taucker", email: "paul@taucker.com", num: 12345 }, { fname: "Steven", lname: "Spil", email: "steven@spil.com", num: 87654 }, { fname: "computer", lname: "Tech", email: "comp@tech.com", num: 45158 }, { fname: "User", lname: "Interface", email: "user@inter.in", num: 94979 }]; var rows = data_list.length; for (i = 0, l = rows; i < rows; i++) { data.items.push(lang.mixin({ id: i + 1 }, data_list[i % l])); } var dataStore = new dojo.data.ItemFileWriteStore({ data: data }); var layout = [{ type: "dojox.grid._CheckBoxSelector", width: '30px' }, [{ 'name': 'Sl', 'field': 'id', 'width': '20px', 'editable': 'false' }, { 'name': 'Firstname', 'field': 'fname', 'width': '140px', 'editable': 'true' }, { 'name': 'Lastname', 'field': 'lname', 'width': '130px', 'editable': 'true' }, { 'name': 'Email', 'field': 'email', 'width': '140px', 'editable': 'true' }, { 'name': 'Number', 'field': 'num', 'width': '80px', 'editable': 'true' }] ]; var grid = new DataGrid({ store: dataStore, query: { id: "*" }, queryOptions: {}, structure: layout }); grid.placeAt("gridDiv"); grid.startup(); var button = new Button({ label: "Add Row", }, "addRow"); button.startup(); var button = new Button({ label: "Delete", }, "deleteBtn"); button.startup(); dojo.connect(deleteBtn, "onclick", function() { var items = grid.selection.getSelected(); if (items.length) { dojo.forEach(items, function(selectedItem) { if (selectedItem !== null) { dataStore.deleteItem(selectedItem); } }); } }); var form = new Form({ onSubmit: function(evt) { evt.preventDefault(); var formValue = form.get("value"); console.debug(formValue); dataStore.fetch({ onComplete: function(allItems) { var newId = allItems.length + 1; dataStore.newItem({ id: newId, fname: formValue.first, lname: formValue.last, email: formValue.dob, num: formValue.mobile }); } }) } }, "myForm"); form.startup(); }); 
 *, th { font: 14px'verdana', sans-serif; } td { font: 13px'verdana', sans-serif; } #gridDiv { height: 14em; margin-bottom: 15px; width: 42em; } 
 <script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js" data-dojo-config="parseOnLoad:true"></script> <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/resources/dojo.css"> <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/claro/claro.css"> <link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojox/grid/resources/claroGrid.css"> <div class="claro"> <div id="gridDiv"></div> <button id="deleteBtn"></button> <form id="myForm"> <div id="formContainer"> <input type="text" id="first" name="first" data-dojo-type="dijit/form/TextBox" value="" placeholder="Firstname" required/> <input type="text" id="last" name="last" data-dojo-type="dijit/form/TextBox" value="" placeholder="Lastname" required /> <input type="text" id="email" name="dob" data-dojo-type="dijit/form/TextBox" value="" placeholder="Email" required /> <input type="text" id="mobile" name="mobile" data-dojo-type="dijit/form/TextBox" value="" placeholder="Mobile Number" required /> </div> <button type="submit" value="submit" data-dojo-type="dijit/form/Button" id="submitForm">Add Row</button> </form> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM