同一页上的多个DataTable具有不同的ajax源 [英] Multiple DataTables on the same page with different ajax sources

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

问题描述

使用 dataTables ,我在单个页面上有几张表。每个需要拥有它自己的'sAjaxSource'。我似乎无法弄清楚如何做到这一点。这是我的最小代码:

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

这基本上是裸骨设置。每个表都是datatable类和唯一的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隐藏的字幕标签,并包含Ajax源URL。它遍历每个实例并抓取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.

这似乎到目前为止!

推荐答案

不行?它使用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
             }
        });

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

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