问题
I have a text box and add button. Once the user enters some value in the text box and clicks the add button the text box value should be stored in jqgrid. But the text box value is not getting painted in jqgrid How to achieve this..?
This is the aspx code:
<div>
<table>
<tr>
<td>
<span class="SubHeading">Users </span></td>
<td>
<asp:TextBox ID="txt_users" runat="server" />
</td>
<td>
<asp:Button ID="btn_addusers" Text="Add" style="margin-left: 10px;"runat="server" />
</td>
</tr>
</table>
<div>
This is the js code:
$(document).ready(function() {
$("#btn_addusers").click(function() {
$("#users_grid").trigger("reloadGrid");
var mydata = $('#txt_users').val();
$("#users_grid").jqGrid({
datatype: "local",
data: mydata,
gridview: true,
height: 'auto',
width: 'auto',
colNames: ['User ID'],
colModel: [
{ name: 'userid', width: 180 }
],
caption: "Users in Private space"
});
return false;
});
});
回答1:
you should move the definition of jqGrid
out of the click
handle. The grid can be created once. If the user need to add a row to the grid you can use addRowData
. Alternatively you can use addRow
which add empty row in the grid. You can also use inlineNav
to integrate "Add" button in the navigator bar of grid. If you would use toppager: true option you would have the pager on top instead of on bottom of the grid. See the answer and this one for details.
来源:https://stackoverflow.com/questions/13411956/add-new-row-to-a-jqgrid