无法使用数据表停止初始排序
Unable to stop initial sorting using datatables
我正在使用 datatables 1.10.7.
这里引用了我原来的问题Question on datatables forum
我想禁用 datatables 自动执行的初始排序。
数据tables拒绝收听
"aaSorting": []
或
"aaSorting": [[0,'desc'],[1,'desc']]
它按 table 中的第一列按 ASC 顺序排序。阻止这种情况的唯一方法是使用
"bSort": false
然而,这会删除我 table 上的所有排序功能。
我的 table 对除排序以外的所有其他事情都 100% 有效。过滤、搜索、分页等工作 100%。当我设置
"bSort" : true
或者,当我忽略它时,因为我相信默认值是真的,我在警告消息中收到以下错误:
"error":"An SQL error occurred: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY column1 ASC LIMIT 0, 10' at line 4"
我尝试过使用和不使用 aSorting,使用和不使用 bSort,并以各种方式将它们混合在一起。
有帮助吗?
PS,这是我的 table 定义:
oTable = $('#table_demo').DataTable(
{
"bSort": true,
"aaSorting": [[0,'desc'],[1,'desc']],
"bJQueryUI": true,
"bPaginate": true,
"bStateSave": true,
"processing": true,
"serverSide": true,
"sPaginationType": "full_numbers",
"ajax":
{
"url": "view_demo_remote.php",
"data":
{
"field1": "".$_SESSION['field1']."",
"field2": "".$_SESSION['field2']."",
"field3": "".$_SESSION['field3'].""
}
},
"columns":[
{ "bSortable": true, "data": "col1" },
{ "bSortable": true, "data": "col2" },
{ "bSortable": true, "data": "col3" },
{ "bSortable": false, "data": "col4" },
{ "bSortable": false, "data": "col5" },
{ "bSortable": false, "data": "col6" }
],
"fnCreatedRow": function( nRow, aData, iDataIndex )
{
$(nRow).attr("attrname",aData["col1"]);
},
"fnDrawCallback": function( oSettings )
{
}
});
编辑:
我也尝试使用最新的 api 中的这个,但没有成功:
"order": []
编辑:
这是我的 view_demo_remote.php 服务器端处理:
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
session_start();
$table = 'table_demo';
$primaryKey = 'id';
$field1 = mysql_real_escape_string($_REQUEST["field1"]);
$field2 = mysql_real_escape_string($_REQUEST["field2"]);
$field3 = mysql_real_escape_string($_REQUEST["field3"]);
$columns = array(
array(
'db' => 'id',
'dt' => 'DT_RowId',
'formatter' => function( $d, $row )
{
return $d;
}
),
array( 'db' => 'name', 'dt' => 'col1' ),
array( 'db' => 'surname', 'dt' => 'col2' ),
array( 'db' => 'title', 'dt' => 'col3' ),
array( 'db' => 'date', 'dt' => 'col4' ),
array( 'db' => 'telephone', 'dt' => 'col5' ),
array( 'db' => 'email', 'dt' => 'col6' )
);
$sql_details = array(
'user' => DBUSER,
'pass' => DBUSERPASS,
'db' => DBNAME,
'host' => DBHOST
);
require( 'libraries/DataTables-1.10.7/examples/server_side/scripts/ssp.class.php' );
echo json_encode(SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, "","name <>'' ORDER BY id DESC, datecreated DESC"));
您是否尝试过调用 order 方法?
var table = $('#example').DataTable();
// Sort by column 1 and then re-draw
table
.order( [] )
.draw();
使用 order 指定不应该出现初始排序是完全可以的,请参见下面的示例:
$('#example').dataTable( {
"order": []
} );
您的 PHP 代码调用 SSP::complex
时出错。这些函数需要以下参数
static function complex ( $request, $conn, $table, $primaryKey, $columns, $whereResult=null, $whereAll=null )
但您为 $whereAll
参数指定了 "name <>'' ORDER BY id DESC, datecreated DESC"
。
如果排序被禁用,这可能会起作用,但当它不是并且另一列被排序时,SSP
class 将使用两个 ORDER
子句(一个来自 $whereAll
参数和另一个基于正在排序的列)导致 SQL 错误。
将 "name <>'' ORDER BY id DESC, datecreated DESC"
替换为 "name <>''"
以更正此问题。
我正在使用 datatables 1.10.7.
这里引用了我原来的问题Question on datatables forum
我想禁用 datatables 自动执行的初始排序。
数据tables拒绝收听
"aaSorting": []
或
"aaSorting": [[0,'desc'],[1,'desc']]
它按 table 中的第一列按 ASC 顺序排序。阻止这种情况的唯一方法是使用
"bSort": false
然而,这会删除我 table 上的所有排序功能。
我的 table 对除排序以外的所有其他事情都 100% 有效。过滤、搜索、分页等工作 100%。当我设置
"bSort" : true
或者,当我忽略它时,因为我相信默认值是真的,我在警告消息中收到以下错误:
"error":"An SQL error occurred: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY column1 ASC LIMIT 0, 10' at line 4"
我尝试过使用和不使用 aSorting,使用和不使用 bSort,并以各种方式将它们混合在一起。
有帮助吗?
PS,这是我的 table 定义:
oTable = $('#table_demo').DataTable(
{
"bSort": true,
"aaSorting": [[0,'desc'],[1,'desc']],
"bJQueryUI": true,
"bPaginate": true,
"bStateSave": true,
"processing": true,
"serverSide": true,
"sPaginationType": "full_numbers",
"ajax":
{
"url": "view_demo_remote.php",
"data":
{
"field1": "".$_SESSION['field1']."",
"field2": "".$_SESSION['field2']."",
"field3": "".$_SESSION['field3'].""
}
},
"columns":[
{ "bSortable": true, "data": "col1" },
{ "bSortable": true, "data": "col2" },
{ "bSortable": true, "data": "col3" },
{ "bSortable": false, "data": "col4" },
{ "bSortable": false, "data": "col5" },
{ "bSortable": false, "data": "col6" }
],
"fnCreatedRow": function( nRow, aData, iDataIndex )
{
$(nRow).attr("attrname",aData["col1"]);
},
"fnDrawCallback": function( oSettings )
{
}
});
编辑:
我也尝试使用最新的 api 中的这个,但没有成功:
"order": []
编辑:
这是我的 view_demo_remote.php 服务器端处理:
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
session_start();
$table = 'table_demo';
$primaryKey = 'id';
$field1 = mysql_real_escape_string($_REQUEST["field1"]);
$field2 = mysql_real_escape_string($_REQUEST["field2"]);
$field3 = mysql_real_escape_string($_REQUEST["field3"]);
$columns = array(
array(
'db' => 'id',
'dt' => 'DT_RowId',
'formatter' => function( $d, $row )
{
return $d;
}
),
array( 'db' => 'name', 'dt' => 'col1' ),
array( 'db' => 'surname', 'dt' => 'col2' ),
array( 'db' => 'title', 'dt' => 'col3' ),
array( 'db' => 'date', 'dt' => 'col4' ),
array( 'db' => 'telephone', 'dt' => 'col5' ),
array( 'db' => 'email', 'dt' => 'col6' )
);
$sql_details = array(
'user' => DBUSER,
'pass' => DBUSERPASS,
'db' => DBNAME,
'host' => DBHOST
);
require( 'libraries/DataTables-1.10.7/examples/server_side/scripts/ssp.class.php' );
echo json_encode(SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, "","name <>'' ORDER BY id DESC, datecreated DESC"));
您是否尝试过调用 order 方法?
var table = $('#example').DataTable();
// Sort by column 1 and then re-draw
table
.order( [] )
.draw();
使用 order 指定不应该出现初始排序是完全可以的,请参见下面的示例:
$('#example').dataTable( {
"order": []
} );
您的 PHP 代码调用 SSP::complex
时出错。这些函数需要以下参数
static function complex ( $request, $conn, $table, $primaryKey, $columns, $whereResult=null, $whereAll=null )
但您为 $whereAll
参数指定了 "name <>'' ORDER BY id DESC, datecreated DESC"
。
如果排序被禁用,这可能会起作用,但当它不是并且另一列被排序时,SSP
class 将使用两个 ORDER
子句(一个来自 $whereAll
参数和另一个基于正在排序的列)导致 SQL 错误。
将 "name <>'' ORDER BY id DESC, datecreated DESC"
替换为 "name <>''"
以更正此问题。