duana1021 2018-10-08 12:58
浏览 69

数据表:是否可以使用Ajax填充2列并对其他列使用不同的方式?

I have a table with send mail info, I use Smarty, a PHP engine, to fill this table.

I want to add 2 other columns with open and click ratios (of the mailings). I use an API to get this information in PHP, but because the API is slow I first want to load the normal columns and then when it's loaded I want to load the other 2 columns, is this possible in any way?

Basically, Can I fill a data table with 5 columns and when that's done add 2 more with ajax?

Right now I use 1 ajax call to get everything.

  • 写回答

1条回答 默认 最新

  • douzhantanju1849 2018-10-09 14:53
    关注

    This is definitely something you can do. I have had a lot of success using the columns option in creating and populating my table. I use a buildTable function where I pass the results of an AJAX call, the variable here is called dataList, and use the object to build the table as follows. In this example the value for data is the name of the field in the dataList variable whose value I would like to appear in the table. In your case I would expect dataList to be the results from your database.

    Note that both the title and data fields can take functions or html as input so you could either make an AJAX call in this field, or input a placeholder div to append the results to later using JQuery or whatever you liked.

    $("#table-main").DataTable({
            //options
            columns: [
                {
                    data: "data1",
                    title: "columnName"
                },
                {
                    data: "data2",
                    title: "columnName"
    
                },
                {
                    data: "data3",
                    title: "columnName"
                },
                {
                    data: "<div id='ajax_result_holder'></div>",
                    title: "columnName"
                },
                {
                    data: function(row, type, set){
                          //make AJAX call, return result
                    },
                    title: "columnName"
                },
            ],
            data: dataList
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据