本文介绍了YADCF + 数据表服务器端用 PHP 填充选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实搜索了提到该论点的每一页,但似乎无法弄清楚这一点我正在使用带有 Yadcf、ajax 源、server_side.php 和 ssp.class.php 的数据表

I literally have searched Every Single Page that mentions the argument, but cant seem to figure this one outI am using Datatables with Yadcf , ajax source, server_side.php and ssp.class.php

现在我想用所有数据填充选择过滤器,而不仅仅是当前页面,我阅读并看到了 yadcf 展示 --> yadcf-showcase.appspot.com/server_side_source.html 唯一提到的是用于填充 yadcf_data_n 的 JQuery (java) 部分

Now i want to populate the select filters with All the data, not just the current page,I read and saw the yadcf showcase --> yadcf-showcase.appspot.com/server_side_source.html that the only mention is a JQuery (java) part to populate the yadcf_data_n

但是找不到一个例子来使用 server_side.php 和 ssp.class.php 来检索数据.

But cant find one single example to do the same using the server_side.php and ssp.class.php to retrieve the data.

我(以及我在很多其他人周围看到的)如果能有一个关于如何存档此内容的盗版示例,那就太棒了

I (and from what i saw around a lot of other people) would be really great full to have a piratical example on how to archive this

我的数据表代码是:

  var oTable2;
  oTable2 = $('#example2').DataTable({
            "responsive": true,
            "processing": true,
            select: true,
            "serverSide":true,
            stateSave: true,
            "ajax": {
               "type" : "GET",
               "url":  "leadsdata.php",
               "data" :  function ( d ) {
                d.var1=var1;
                   }

            },
            "columns": [{
                "data":"test",
                "mRender": function ( client_id, type, full )  {
                return  '<a href="clickme.php?id='+Base64.encode(client_id)+'"> GO</a>';
                }
        },{
                "data": 1
        },{
                "data": 2
        },{
                "data": 3
        },{
                "data": 4
        },{
                "data": 5
        },{
                "data": 6

  }],
            "language": {
               "infoFiltered": ".",
               "info": "_START_ : _END_ nga _TOTAL_ nominativ"
             }

   });

    yadcf.init(oTable2, [{
            column_number: 1,
                  filter_type: "text",
                  filter_delay: 200
            }, {
            column_number: 2,
                  filter_type: "text",
                  filter_delay: 200
            }, {
            column_number: 3
            }, {
            column_number: 4,
                filter_type: "text",
                filter_delay: 200
            }, {
            column_number: 5

            }, {
            column_number: 6

            }]);

    });

并使用默认的 server_side.php 点击这里显示

And using the default server_side.php Click here to show

和默认的 ssp.class.php 点击此处显示

and the default ssp.class.php Click here to show

欢迎任何如何从这个设置填充 yadcf_data_n# 的示例代码

Any sample code how to populate the yadcf_data_n# from this setup is welcomed

推荐答案

适合对同一主题感兴趣的任何人

Well for anyone interested in the same topic

感谢 vedmack (YADCF) 作者的帮助,我找到了完美的解决方案:

Thanks for the help of vedmack (YADCF) author i found the perfect solution:

修改部分:

    echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

到:

$data=SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery, $extraWhere );

$db = SSP::sql_connect( $sql_details );
$stmt3 = $db->prepare( 'SELECT DISTINCT(value) FROM esito' );
$stmt3->execute();
$data['yadcf_data_3'] = $stmt3->fetchAll(PDO::FETCH_COLUMN, 0);

$stmt5 = $db->prepare( 'SELECT DISTINCT(value2) FROM table' );
$stmt5->execute();
$data['yadcf_data_5'] = $stmt5->fetchAll(PDO::FETCH_COLUMN, 0);

$stmt6 = $db->prepare( 'SELECT DISTINCT(value3) FROM table' );
$stmt6->execute();
$data['yadcf_data_6'] = $stmt6->fetchAll(PDO::FETCH_COLUMN, 0);


echo json_encode($data);

所以我们为我们拥有的每个选择字段进行自定义查询(在我的情况下我有 3 个)并重新包含 $db,因为我在不同的文件中有我的 ssp.class.php

So we make a custom query for each select field we have (In my case i had 3)And re-include the $db since i have my ssp.class.php in different file

希望能帮到你

这篇关于YADCF + 数据表服务器端用 PHP 填充选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 21:04