如何实现jquery表插件

时间:2014-03-17 04:13:21

标签: javascript jquery

我想在我的表中实现一个表分类器jquery插件。链接到http://www.matanhershberg.com/plugins/jquery-animated-table-sorter/

但是在网站上显示的示例中,他们已经有了一张桌子。但对我来说情况并非如此。对我来说,当我点击页面上的按钮时,表格出现了。所以,我想问一下,我应该在哪里添加用于排序表的javascript排序函数。所以,它被排序了。

1 个答案:

答案 0 :(得分:0)

如果您在单击按钮时表格是ajax,那么在您的ajax成功回调函数中,在绘制表格之后,然后应用插件...

//example jQuery ajax call
$.ajax({
    type: "[post or get]",
    url: "[your url]",
    data: $(".form").serialize(),
    dataType: "html",
    success: function (data) {
        //your code that draws your table
        //now apply the plugin to your table
        $('table.tableSorter').tableSort( {
            sortBy: ['numeric', 'text', 'text', 'numeric', 'numeric', 'numeric']
        });
    }
});

但是如果你的表最初已经在页面中,但它只是隐藏了,那么在文档准备好之后应用插件,就像插件演示页一样。