如何将记录添加到jTable? [英] How to add record to jTable?

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

问题描述

我可以知道如何从json或数组向jtable添加记录吗?

May I know how to add a record to jtable from json or array?

我只能从API参考中找到两种方法

I can find only two methods from API Reference

我同时尝试了两种方法,但没有用,它总是显示无可用数据!"

I tried both, but not work, it always shows "No data available!"

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="jqueryui/ui/jquery-ui.js"></script>
<script src="jquery.jtable.js"></script>

<link rel="stylesheet" type="text/css" href="themes/basic/jtable_basic.css" />
<script>
jQuery(document).ready
(
    function()
    {
        var jt=$('#jt').jtable
        (
            {
                title: 'this is title',
                fields: {
                    a: {
                        title: 'a'
                    },
                    b: {
                        title: 'b'
                    }
                }
            }
        );
        jt.jtable('load',{a:'aaa',b:'bbb'});

        jt.jtable('addRecord', {
            record: {
                a:'aaa',b:'bbb'
            }
        });
    }
);
</script>
</head>
<body>

<div id="jt">

</div>

</body>
</html>

推荐答案

load方法用于从服务器检索表中数据的情况.如果要手动添加数据,则addRecord是正确的使用方法.但是:默认情况下,jtable也会尝试向服务器添加数据.如果您的服务器配置不正确,则addRecord也会失败.

load method is used when you want to retrieve data to your table from server. If you want to add data by hand then addRecord is the right method to use. However: by default, jtable tries to add data also to server. If you don't have your server configured properly, then addRecord may fail too.

在这种情况下,如果您只想手动将数据添加到客户端,请为addRecord提供clientOnly参数:

In this, if you just want to add data manually to the client side, provide addRecord with clientOnly parameter:

$('#jt').jtable('addRecord', {
   record: {
      a:'aaa',b:'bbb'
   },
   clientOnly: true
});

完整的演示示例: JSFIDDLE

这篇关于如何将记录添加到jTable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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