How to add record to jTable?

浪尽此生 提交于 2019-12-07 14:18:31

问题


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

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>

回答1:


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.

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
});

Full working demo: JSFIDDLE




回答2:


Are you trying to add the data locally? According to the documentation for addRecord, you would need to specify the clientOnly option:

clientOnly (boolean, default: false): If this is true, jTable does not add record to the server, only adds to the table.



来源:https://stackoverflow.com/questions/18081930/how-to-add-record-to-jtable

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