添加新行到的jqGrid [英] Add new row to a jqgrid

查看:93
本文介绍了添加新行到的jqGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,并添加按钮。一旦用户输入在文本框中输入一些值,并点击添加按钮的文本框的值应该存储在jqGrid的。但文本框的值是没有得到涂上的jqGrid如何做到这一点..?

这是ASPX code:

 < D​​IV>
    <表>
         &所述; TR>
             &所述; TD>
              <跨度类=副标题>用户< / SPAN>< / TD>
              &所述; TD>
              < ASP:文本框ID =txt_users=服务器/>
              < / TD>
               &所述; TD>
              < ASP:按钮的ID =btn_addusers文本=添加的风格=保证金左:10px的;=服务器/>                < / TD>                 < / TR>
    < /表>
    < D​​IV>

这是JS code:

  $(文件)。就绪(函数(){
    $(#btn_addusers)。点击(函数(){
        $(#users_grid)的触发器(reloadGrid);        VAR MYDATA = $('#txt_users)VAL()。
        $(#users_grid)。jqGrid的({
            数据类型:本地,
            数据:MYDATA,
            GridView控件:真实,
            高度:'自动',
            宽度:'自动',
            colNames:用户ID'],
            colModel:
        {名称:'用户ID',宽度:180}
    ]            标题:在私人空间用户
        });
        返回false;    });
});


解决方案

您应该将的jqGrid 定义的的的<$ C的$ C>点击句柄。网格可以被创建的一次的。如果用户需要将一行添加到您可以使用 addRowData 电网。或者您可以使用 addRow 里面加的的行中的网格。您还可以使用 inlineNav 来整合网格的导航栏中的添加按钮。如果你想使用 toppager:真选项,您将有寻呼机在顶部,而不是对电网的底部。请参见答案这一个的详情。

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;

    });
});

解决方案

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.

这篇关于添加新行到的jqGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆