YADCF + Datatables服务器端用PHP填充Select [英] YADCF + Datatables Server Side Populate Select with 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 out I am using Datatables with Yadcf , ajax source, server_side.php and ssp.class.php
现在,我想用所有数据(不仅是当前页面)填充选择过滤器, 我阅读并看到了yadcf展示柜--> yadcf-showcase.appspot.com/server_side_source.html ,唯一提到的是JQuery(java)部分,用于填充 yadcf_data_n
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
推荐答案
对同一主题感兴趣的人
感谢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 + Datatables服务器端用PHP填充Select的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!