YADCF + Datatables Server Side Populate Select with Php

一笑奈何 提交于 2020-01-11 06:19:01

问题


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

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

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

My datatables code is :

  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

            }]);

    });

And using the default server_side.php Click here to show

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

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


回答1:


Well for anyone interested in the same topic

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

modify the part from :

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

to:

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

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

Hope it helps



来源:https://stackoverflow.com/questions/41507443/yadcf-datatables-server-side-populate-select-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!