jqGrid-重新加载数据 [英] jqGrid—Reloading Data

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

问题描述

我试图将一个项目添加到我的数据源中,然后根据

I'm trying to add an item to my data source, and then re-load the grid based on this answer. The grid loads fine. The addItemToGrid gets called a few times, and I'm verifying that the underlying tableSrc object is getting added to, but the grid remains unchanged.

    var tableSrc = { "rows": [
        { "title": "Title1", "subtitle": "subTitle", "authors": ["a1", "a2", "a3"] },
        { "title": "Title2", "subtitle": "subtitle", "authors": ["X", "Y"] },
        { "title": "Title3", "subtitle": "subTitle", "authors": ["1", "2", "3", "4"]}]
    };

    targetGrid = $("#jqGridElement").jqGrid({
        datastr: tableSrc,
        jsonReader: { repeatitems: false },
        datatype: "jsonstring",
        colNames: ['title', 'subtitle'],
        colModel: [
            { name: 'title', index: 'title', width: 55 },
            { name: 'subtitle', index: 'subtitle'}],
        height: 'auto',

        gridview: true
    });

    function addItemToGrid() {
        tableSrc.rows.push({ "title": "NEW", "subtitle": "HELLO", "authors": ["1", "2", "3", "4"] });
        $("#jqGridElement").trigger('reloadGrid');
        //$("#jqGridElement").jqGrid('reloadGrid');
    }

推荐答案

首先,语句$("#jqGridElement").trigger('GridUnload')不执行任何操作,因为没有名称为'GridUnload'的事件. jqGrid当前支持的唯一事件是'reloadGrid'.该事件支持您感兴趣的其他参数(请参见此处).调用$("#jqGridElement").trigger("reloadGrid", [{current:true}]);将刷新网格,但是不会改变可能会使用户产生的选择.

First, the statement $("#jqGridElement").trigger('GridUnload') do nothing because there are no event with the name 'GridUnload'. The only event currently supported by jqGrid is 'reloadGrid'. The event support additional parameters (see here) which can be interesting for you. The call $("#jqGridElement").trigger("reloadGrid", [{current:true}]); will refresh the grid, but the selection which could make the user will be not changed.

如果您需要在新型API"中调用GridUnload,它应该看起来像

If you need call GridUnload in "new style API" it should looks like

$("#jqGridElement").jqGrid('GridUnload');

调用GridUnload方法后,将重新创建作为jqGrid基础的table元素.因此,如果将$("#jqGridElement")保存在变量中(例如var gridObj = $("#jqGridElement")),则应刷新值(分配为gridObj = $("#jqGridElement")).

After you call GridUnload method the table element which is basis of jqGrid will be recreated. So if you saved the $("#jqGridElement") in a variable (var gridObj = $("#jqGridElement") for example) you should refresh the value (with the assignment gridObj = $("#jqGridElement")).

现在关于您的主要问题.如果您需要在网格中添加新列或在旧网格的位置上绝对是另一个网格,则GridUnload方法很有用. (请参见答案

Now about your main question. The method GridUnload is useful in the case if you need add new column to the grid or create on the place of old grid absolutely another grid. (see the answer or this one as an example). If you need to add one row of data to the existing grid you can use addRowData for example.

对您来说真正重要的是了解每行ID(<tr>元素)的用法.如果您不想自己管理ID,则可以在undefined用作rowid. array_data"rel =" nofollow noreferrer> addRowData 方法.在这种情况下,$.jgrid.randId()方法将在内部用于为新行生成唯一的ID.

What can be really important to you to understand is the usage of ids for every row (<tr> element). If you don't want to manage ids yourself you can use undefined as the rowid in the addRowData method. In the case the $.jgrid.randId() method will be used internally to generate unique id for the new row.

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

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