Jquery 使用服务器端dataTable | PHP、SQL Server进行下拉选择
在服务器端数据表中选择下拉列表时出现问题。这基于以下示例: 我有关于如何修复它的指南,但我不知道如何设置它。 我正在使用SQL Server 2012、XAMPP,并通过SQLSRV连接 数据表似乎工作正常 它将所有结果过滤到下拉列表中 我的问题是,当我选择其中一个下拉列表时,它显示没有找到匹配项的结果 这是我的密码 我的桌子Jquery 使用服务器端dataTable | PHP、SQL Server进行下拉选择,jquery,sql,ajax,datatable,datatables,Jquery,Sql,Ajax,Datatable,Datatables,在服务器端数据表中选择下拉列表时出现问题。这基于以下示例: 我有关于如何修复它的指南,但我不知道如何设置它。 我正在使用SQL Server 2012、XAMPP,并通过SQLSRV连接 数据表似乎工作正常 它将所有结果过滤到下拉列表中 我的问题是,当我选择其中一个下拉列表时,它显示没有找到匹配项的结果 这是我的密码 我的桌子 <div class="box-body"> <table id="example" class="table table-bordered"
<div class="box-body">
<table id="example" class="table table-bordered" style="width:100%">
<thead>
<tr>
<th>Series No</th>
<th>Account Type</th>
<th>Tools</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Series No</th>
<th>Account Type</th>
<th>Tools</th>
</tr>
</tfoot>
</table>
</div>
这是我的剧本
<script>
$(function() {
$('#example').DataTable( {
dom: "Bfrtip",
ajax: {
url: "account_type_table.php",
type: "POST"
},
serverSide: true,
columns: [
{ data: "seriesno" },
{ data: "accounttype" },
{ "data": "seriesno", "name": " ", "autoWidth": true, "render": function (data, type, full, meta) {
return "<button class='btn btn-success btn-sm btn-flat edit' data-id='"+full.seriesno+"'><i class='fa fa-edit'></i> Edit</button> <button class='btn btn-danger btn-sm btn-flat delete' data-id='"+full.seriesno+"'><i class='fa fa-trash'></i> Delete</button>";}
}
],
initComplete: function () {
this.api().columns().every( function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo( $(column.footer()).empty() )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
},
select: false,
buttons: [],
} );
} );
这是我的服务器端桌子
<?php
/*
* Example PHP implementation used for the index.html example
*/
// DataTables PHP library
include( "../dataTables/table_account_type/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'accounttype' )
->fields(
Field::inst( 'seriesno' )
->validator( Validate::notEmpty( ValidateOptions::inst()
->message( 'A first name is required' )
) ),
Field::inst( 'accounttype' )
->validator( Validate::notEmpty( ValidateOptions::inst()
->message( 'A last name is required' )
) )
)
->process( $_POST )
->json();
?>
这里有什么问题吗?这是因为我的过滤器仅在数据显示在代码本身中时才起作用,并且它无法识别来自服务器端的数据吗?您所指的是静态数据,并且在UI本身中进行过滤
但在您的情况下,您使用的是服务器端处理,这意味着
排序逻辑应由服务器端代码处理
InTebug方法考虑API返回的数据并填充组合框,这是它需要做的。 使其按照您的要求工作
不要使用服务器端处理,并按照中的说明一次加载所有数据 如果需要使用服务器端处理 您可能需要自定义initComplete函数来调用另一个API,该API返回并加载所有唯一的列数据 注意:当您从combobox中选择一个值时,您可能还需要编写逻辑 我确信Datatable会将选定的组合值作为参数添加到API中,并基于此,您需要在后端处理数据并返回适当的响应 您指的是具有静态数据并且在UI本身中进行过滤的用户 但在您的情况下,您使用的是服务器端处理,这意味着 排序逻辑应由服务器端代码处理InTebug方法考虑API返回的数据并填充组合框,这是它需要做的。 使其按照您的要求工作
不要使用服务器端处理,并按照中的说明一次加载所有数据 如果需要使用服务器端处理 您可能需要自定义initComplete函数来调用另一个API,该API返回并加载所有唯一的列数据 注意:当您从combobox中选择一个值时,您可能还需要编写逻辑 我确信Datatable会将选定的组合值作为参数添加到API中,并基于此,您需要在后端处理数据并返回适当的响应这很痛苦,对主代码进行了大量的编辑。我会调查的。非常感谢。这很痛苦,对主代码进行了大量的编辑。我会调查的。非常感谢。