不同的AJAX源在同一页面上的多个数据表 [英] Multiple DataTables on the same page with different ajax sources

查看:168
本文介绍了不同的AJAX源在同一页面上的多个数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用数据表在单页上几个表。两国都必须有它自己的sAjaxSource。我似乎无法弄清楚究竟是如何做到这一点。下面是最小的code,我有:

I have several tables on a single page using dataTables. Each needs to have it's own 'sAjaxSource'. I can't seem to figure out exactly how to do this. Here's the minimal code I have:

         var oTable = $('.datatable').dataTable( {
                "bProcessing": true,
                "sAjaxSource": "/ajax/function",
                "bSort": false,
                "fnDrawCallback": function() {
                       //some click events initilized here
                 }
            });

这基本上是裸骨设置。每个表的数据表类和一个唯一的ID。但不知道如何改变AjaxSource,基于特定的表。

This is basically the bare bone setup. Each table as the datatable class and a unique ID. But not sure how to change the AjaxSource, based on a specific table.

感谢您!

编辑:

下面就是我最后做:

        $('.datatable').each(function(index){

             $('#'+$(this).attr('id')).dataTable( {
                "bProcessing": true,
                "sAjaxSource": $(this).children('caption').html(),
                "bSort": false,
                "fnDrawCallback": function() {
                 }
            });
        });

里面的桌子,我把由CSS隐藏的,包含了阿贾克斯源URL标题标签。它遍历每个实例,并抓住了网址。

Inside the table I put a caption tag that is hidden by css and contains the Ajax Source URL. It iterates through each instance and grabs the url.

这似乎到目前为止是工作!

This seems to be working so far!

推荐答案

这会无法正常工作?它使用的ID而不是类唯一地标识每个数据表并附加一个单独的源,以根据id每个表

Will this not work? It uses the id rather than the class to uniquely identify each data table and attaches a separate source to each table based on the id.

  var oTable = $('#FirstDataTableID').dataTable( {
            "bProcessing": true,
            "sAjaxSource": "/ajax/function",
            "bSort": false,
            "fnDrawCallback": function() {
                   //some click events initilized here
             }
        });

  var oTable = $('#SecondDataTableID').dataTable( {
            "bProcessing": true,
            "sAjaxSource": "/ajax/other_function",
            "bSort": false,
            "fnDrawCallback": function() {
                   //some click events initilized here
             }
        });

这篇关于不同的AJAX源在同一页面上的多个数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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