Add new row to a jqgrid

谁说胖子不能爱 提交于 2020-01-16 10:16:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!