首先我得到了css,datatables.js然后我从ajax流水线代码开始,然后我初始化它 - 这里是:
<link href="tablesorter/tablesortingStyle.css" rel="stylesheet" />
<script type="text/javascript" src="tablesorter/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" class="init">
$.fn.dataTable.pipeline = function ( opts ) {
var conf = $.extend( {
pages: 5,
url: '',
data: null,
method: 'GET'
}, opts );
var cacheLower = -1;
var cacheUpper = null;
var cacheLastRequest = null;
var cacheLastJson = null;
return function ( request, drawCallback, settings ) {
var ajax = false;
var requestStart = request.start;
var drawStart = request.start;
var requestLength = request.length;
var requestEnd = requestStart + requestLength;
if ( settings.clearCache ) {
ajax = true;
settings.clearCache = false;
}
else if ( cacheLower < 0 || requestStart < cacheLower || requestEnd > cacheUpper ) {
ajax = true;
}
else if ( JSON.stringify( request.order ) !== JSON.stringify( cacheLastRequest.order ) ||
JSON.stringify( request.columns ) !== JSON.stringify( cacheLastRequest.columns ) ||
JSON.stringify( request.search ) !== JSON.stringify( cacheLastRequest.search )
) {
ajax = true;
}
cacheLastRequest = $.extend( true, {}, request );
if ( ajax ) {
if ( requestStart < cacheLower ) {
requestStart = requestStart - (requestLength* (conf.pages-1));
if ( requestStart < 0 ) {
requestStart = 0;
}
}
cacheLower = requestStart;
cacheUpper = requestStart + (requestLength * conf.pages);
request.start = requestStart;
request.length = requestLength*conf.pages;
if ( $.isFunction ( conf.data ) ) {
var d = conf.data( request );
if ( d ) {
$.extend( request, d );
}
}
else if ( $.isPlainObject( conf.data ) ) {
$.extend( request, conf.data );
}
settings.jqXHR = $.ajax( {
"type": conf.method,
"url": conf.url,
"data": request,
"dataType": "json",
"cache": false,
"success": function ( json ) {
cacheLastJson = $.extend(true, {}, json);
if ( cacheLower != drawStart ) {
json.data.splice( 0, drawStart- cacheLower );
}
json.data.splice( requestLength, json.data.length );
drawCallback( json );
}
} );
}
else {
json = $.extend( true, {}, cacheLastJson );
json.draw = request.draw;
json.data.splice( 0, requestStart-cacheLower );
json.data.splice( requestLength, json.data.length );
drawCallback(json);
}
}
};
$.fn.dataTable.Api.register( 'clearPipeline()', function () {
return this.iterator( 'table', function ( settings ) {
settings.clearCache = true;
} );
});
$(document).ready(function(){
// Login-Logs-Tabelle, wird mit DataTables initialisiert
$('#mylogins').dataTable({
"processing": true,
"serverSide": true,
"language": {
"emptyTable": "Keine Daten verfügbar.",
"info": "Zeige _START_ bis _END_ von _TOTAL_ Einträgen",
"infoEmpty": "Zeige 0 bis 0 von 0 Einträgen",
"infoFiltered": "(gefiltert von _MAX_ insgesamten Einträgen)",
"infoPostFix": "",
"thousands": ",",
"lengthMenu": "Zeige _MENU_ Einträge",
"loadingRecords": "Lade...",
"processing": "Wird verarbeitet...",
"search": "Suche:",
"zeroRecords": "Keine passenden Einträge gefunden",
"paginate": {
"first": "Erste",
"last": "Letzte",
"next": "Nächste",
"previous": "Vorherige"
},
"aria": {
"sortAscending": ": Aktivieren, um die Spalte aufsteigend zu sortieren",
"sortDescending": ": Aktivieren, um die Spalte absteigend zu sortieren"
}
},
"ajax": $.fn.dataTable.pipeline({
url: 'tablesorter/serverside/loginlogs.php',
pages: 5 // Seiten die gecached werden
})
});
});
</script>
我的服务器端脚本是这样的:
<?php
// Datenbank-Tabelle, die verwendet wird
$table = 'loginlogs';
// Der Primary key, der Tabelle
$primaryKey = 'id';
// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple indexes.
$columns = array(
array( 'db' => 'ip', 'dt' => 0 ),
array(
'db' => 'status',
'dt' => 1,
'formatter' => function( $d, $row ) {
if($d == 1){
return "Erfolgreich";
}else{
return "Fehlgeschlagen";
}
}
),
array(
'db' => 'stayloggedin',
'dt' => 2,
'formatter' => function( $d, $row ) {
if($d == 1){
return "Ja";
}else{
return "Nein";
}
}
),
array(
'db' => 'date',
'dt' => 3,
'formatter' => function( $d, $row ) {
return getonlydate($d);
}
),
array(
'db' => 'date',
'dt' => 4,
'formatter' => function( $d, $row ) {
return getonlytime($d);
}
)
);
// SQL server connection information
require('../../phpfuncs/connection.php');
$sql_details = array(
'user' => $user,
'pass' => $pw,
'db' => $db,
'host' => $host
);
require('ssp.class.php');
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
?>
所以我有我的css,js和serverside(php)部分.... 我的错是什么? 我在控制台中没有出现任何错误,它在处理部分被冻结。 我看了网络分析器部分,它已经停止,所以没有任何东西,脚本试图获取或加载。 有人可以帮帮我吗?
顺便说一句,这是我的调试日志: http://debug.datatables.net/urifuz
我在我的测试服务器上使用PHP Version 5.5.11
我昨天无法编辑我的帖子,因为stackoverflow只是处于可读模式。所以现在我做到了。我解决了这个问题。我在服务器端部分使用了两个函数,我需要包含我的functions.php。对于我的坏,控制台没有认识到这一点,所以没有错误。但没有我包括功能,一切正常。