mirror of
https://github.com/DataTables/DataTables.git
synced 2025-02-19 17:54:14 +01:00
New: The ability to customise the property that is read when obtaining Ajax information from the server, for the data to insert into the table. The new initailisation parameter is sAjaxDataProp. It can be used with Ajax sourced data or server-side processing. When Ajax sourced data is used, it can be an empty string in which case it is assumed that an array has been passed into DataTables directly. Note also that it uses the same object data processor as mDataSource, so you can use dot notation to read from nested information (e.g. 'my.data').
This commit is contained in:
parent
1277cfece9
commit
2d0aff2b39
59
examples/ajax/sources/array_only.txt
Normal file
59
examples/ajax/sources/array_only.txt
Normal file
@ -0,0 +1,59 @@
|
||||
[
|
||||
["Trident","Internet Explorer 4.0","Win 95+","4","X"],
|
||||
["Trident","Internet Explorer 5.0","Win 95+","5","C"],
|
||||
["Trident","Internet Explorer 5.5","Win 95+","5.5","A"],
|
||||
["Trident","Internet Explorer 6","Win 98+","6","A"],
|
||||
["Trident","Internet Explorer 7","Win XP SP2+","7","A"],
|
||||
["Trident","AOL browser (AOL desktop)","Win XP","6","A"],
|
||||
["Gecko","Firefox 1.0","Win 98+ / OSX.2+","1.7","A"],
|
||||
["Gecko","Firefox 1.5","Win 98+ / OSX.2+","1.8","A"],
|
||||
["Gecko","Firefox 2.0","Win 98+ / OSX.2+","1.8","A"],
|
||||
["Gecko","Firefox 3.0","Win 2k+ / OSX.3+","1.9","A"],
|
||||
["Gecko","Camino 1.0","OSX.2+","1.8","A"],
|
||||
["Gecko","Camino 1.5","OSX.3+","1.8","A"],
|
||||
["Gecko","Netscape 7.2","Win 95+ / Mac OS 8.6-9.2","1.7","A"],
|
||||
["Gecko","Netscape Browser 8","Win 98SE+","1.7","A"],
|
||||
["Gecko","Netscape Navigator 9","Win 98+ / OSX.2+","1.8","A"],
|
||||
["Gecko","Mozilla 1.0","Win 95+ / OSX.1+",1,"A"],
|
||||
["Gecko","Mozilla 1.1","Win 95+ / OSX.1+",1.1,"A"],
|
||||
["Gecko","Mozilla 1.2","Win 95+ / OSX.1+",1.2,"A"],
|
||||
["Gecko","Mozilla 1.3","Win 95+ / OSX.1+",1.3,"A"],
|
||||
["Gecko","Mozilla 1.4","Win 95+ / OSX.1+",1.4,"A"],
|
||||
["Gecko","Mozilla 1.5","Win 95+ / OSX.1+",1.5,"A"],
|
||||
["Gecko","Mozilla 1.6","Win 95+ / OSX.1+",1.6,"A"],
|
||||
["Gecko","Mozilla 1.7","Win 98+ / OSX.1+",1.7,"A"],
|
||||
["Gecko","Mozilla 1.8","Win 98+ / OSX.1+",1.8,"A"],
|
||||
["Gecko","Seamonkey 1.1","Win 98+ / OSX.2+","1.8","A"],
|
||||
["Gecko","Epiphany 2.20","Gnome","1.8","A"],
|
||||
["Webkit","Safari 1.2","OSX.3","125.5","A"],
|
||||
["Webkit","Safari 1.3","OSX.3","312.8","A"],
|
||||
["Webkit","Safari 2.0","OSX.4+","419.3","A"],
|
||||
["Webkit","Safari 3.0","OSX.4+","522.1","A"],
|
||||
["Webkit","OmniWeb 5.5","OSX.4+","420","A"],
|
||||
["Webkit","iPod Touch / iPhone","iPod","420.1","A"],
|
||||
["Webkit","S60","S60","413","A"],
|
||||
["Presto","Opera 7.0","Win 95+ / OSX.1+","-","A"],
|
||||
["Presto","Opera 7.5","Win 95+ / OSX.2+","-","A"],
|
||||
["Presto","Opera 8.0","Win 95+ / OSX.2+","-","A"],
|
||||
["Presto","Opera 8.5","Win 95+ / OSX.2+","-","A"],
|
||||
["Presto","Opera 9.0","Win 95+ / OSX.3+","-","A"],
|
||||
["Presto","Opera 9.2","Win 88+ / OSX.3+","-","A"],
|
||||
["Presto","Opera 9.5","Win 88+ / OSX.3+","-","A"],
|
||||
["Presto","Opera for Wii","Wii","-","A"],
|
||||
["Presto","Nokia N800","N800","-","A"],
|
||||
["Presto","Nintendo DS browser","Nintendo DS","8.5","C/A<sup>1</sup>"],
|
||||
["KHTML","Konqureror 3.1","KDE 3.1","3.1","C"],
|
||||
["KHTML","Konqureror 3.3","KDE 3.3","3.3","A"],
|
||||
["KHTML","Konqureror 3.5","KDE 3.5","3.5","A"],
|
||||
["Tasman","Internet Explorer 4.5","Mac OS 8-9","-","X"],
|
||||
["Tasman","Internet Explorer 5.1","Mac OS 7.6-9","1","C"],
|
||||
["Tasman","Internet Explorer 5.2","Mac OS 8-X","1","C"],
|
||||
["Misc","NetFront 3.1","Embedded devices","-","C"],
|
||||
["Misc","NetFront 3.4","Embedded devices","-","A"],
|
||||
["Misc","Dillo 0.8","Embedded devices","-","X"],
|
||||
["Misc","Links","Text only","-","X"],
|
||||
["Misc","Lynx","Text only","-","X"],
|
||||
["Misc","IE Mobile","Windows Mobile 6","-","C"],
|
||||
["Misc","PSP browser","PSP","-","C"],
|
||||
["Other browsers","All others","-","-","U"]
|
||||
]
|
59
examples/ajax/sources/custom_prop.txt
Normal file
59
examples/ajax/sources/custom_prop.txt
Normal file
@ -0,0 +1,59 @@
|
||||
{ "test": [
|
||||
["Trident","Internet Explorer 4.0","Win 95+","4","X"],
|
||||
["Trident","Internet Explorer 5.0","Win 95+","5","C"],
|
||||
["Trident","Internet Explorer 5.5","Win 95+","5.5","A"],
|
||||
["Trident","Internet Explorer 6","Win 98+","6","A"],
|
||||
["Trident","Internet Explorer 7","Win XP SP2+","7","A"],
|
||||
["Trident","AOL browser (AOL desktop)","Win XP","6","A"],
|
||||
["Gecko","Firefox 1.0","Win 98+ / OSX.2+","1.7","A"],
|
||||
["Gecko","Firefox 1.5","Win 98+ / OSX.2+","1.8","A"],
|
||||
["Gecko","Firefox 2.0","Win 98+ / OSX.2+","1.8","A"],
|
||||
["Gecko","Firefox 3.0","Win 2k+ / OSX.3+","1.9","A"],
|
||||
["Gecko","Camino 1.0","OSX.2+","1.8","A"],
|
||||
["Gecko","Camino 1.5","OSX.3+","1.8","A"],
|
||||
["Gecko","Netscape 7.2","Win 95+ / Mac OS 8.6-9.2","1.7","A"],
|
||||
["Gecko","Netscape Browser 8","Win 98SE+","1.7","A"],
|
||||
["Gecko","Netscape Navigator 9","Win 98+ / OSX.2+","1.8","A"],
|
||||
["Gecko","Mozilla 1.0","Win 95+ / OSX.1+",1,"A"],
|
||||
["Gecko","Mozilla 1.1","Win 95+ / OSX.1+",1.1,"A"],
|
||||
["Gecko","Mozilla 1.2","Win 95+ / OSX.1+",1.2,"A"],
|
||||
["Gecko","Mozilla 1.3","Win 95+ / OSX.1+",1.3,"A"],
|
||||
["Gecko","Mozilla 1.4","Win 95+ / OSX.1+",1.4,"A"],
|
||||
["Gecko","Mozilla 1.5","Win 95+ / OSX.1+",1.5,"A"],
|
||||
["Gecko","Mozilla 1.6","Win 95+ / OSX.1+",1.6,"A"],
|
||||
["Gecko","Mozilla 1.7","Win 98+ / OSX.1+",1.7,"A"],
|
||||
["Gecko","Mozilla 1.8","Win 98+ / OSX.1+",1.8,"A"],
|
||||
["Gecko","Seamonkey 1.1","Win 98+ / OSX.2+","1.8","A"],
|
||||
["Gecko","Epiphany 2.20","Gnome","1.8","A"],
|
||||
["Webkit","Safari 1.2","OSX.3","125.5","A"],
|
||||
["Webkit","Safari 1.3","OSX.3","312.8","A"],
|
||||
["Webkit","Safari 2.0","OSX.4+","419.3","A"],
|
||||
["Webkit","Safari 3.0","OSX.4+","522.1","A"],
|
||||
["Webkit","OmniWeb 5.5","OSX.4+","420","A"],
|
||||
["Webkit","iPod Touch / iPhone","iPod","420.1","A"],
|
||||
["Webkit","S60","S60","413","A"],
|
||||
["Presto","Opera 7.0","Win 95+ / OSX.1+","-","A"],
|
||||
["Presto","Opera 7.5","Win 95+ / OSX.2+","-","A"],
|
||||
["Presto","Opera 8.0","Win 95+ / OSX.2+","-","A"],
|
||||
["Presto","Opera 8.5","Win 95+ / OSX.2+","-","A"],
|
||||
["Presto","Opera 9.0","Win 95+ / OSX.3+","-","A"],
|
||||
["Presto","Opera 9.2","Win 88+ / OSX.3+","-","A"],
|
||||
["Presto","Opera 9.5","Win 88+ / OSX.3+","-","A"],
|
||||
["Presto","Opera for Wii","Wii","-","A"],
|
||||
["Presto","Nokia N800","N800","-","A"],
|
||||
["Presto","Nintendo DS browser","Nintendo DS","8.5","C/A<sup>1</sup>"],
|
||||
["KHTML","Konqureror 3.1","KDE 3.1","3.1","C"],
|
||||
["KHTML","Konqureror 3.3","KDE 3.3","3.3","A"],
|
||||
["KHTML","Konqureror 3.5","KDE 3.5","3.5","A"],
|
||||
["Tasman","Internet Explorer 4.5","Mac OS 8-9","-","X"],
|
||||
["Tasman","Internet Explorer 5.1","Mac OS 7.6-9","1","C"],
|
||||
["Tasman","Internet Explorer 5.2","Mac OS 8-X","1","C"],
|
||||
["Misc","NetFront 3.1","Embedded devices","-","C"],
|
||||
["Misc","NetFront 3.4","Embedded devices","-","A"],
|
||||
["Misc","Dillo 0.8","Embedded devices","-","X"],
|
||||
["Misc","Links","Text only","-","X"],
|
||||
["Misc","Lynx","Text only","-","X"],
|
||||
["Misc","IE Mobile","Windows Mobile 6","-","C"],
|
||||
["Misc","PSP browser","PSP","-","C"],
|
||||
["Other browsers","All others","-","-","U"]
|
||||
] }
|
174
examples/server_side/scripts/custom_data_property.php
Normal file
174
examples/server_side/scripts/custom_data_property.php
Normal file
@ -0,0 +1,174 @@
|
||||
<?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)
|
||||
*/
|
||||
$aColumns = array( 'engine', 'browser', 'platform', 'version', 'grade' );
|
||||
|
||||
/* Indexed column (used for fast and accurate table cardinality) */
|
||||
$sIndexColumn = "id";
|
||||
|
||||
/* DB table to use */
|
||||
$sTable = "ajax";
|
||||
|
||||
/* Database connection information */
|
||||
$gaSql['user'] = "";
|
||||
$gaSql['password'] = "";
|
||||
$gaSql['db'] = "";
|
||||
$gaSql['server'] = "localhost";
|
||||
|
||||
/* REMOVE THIS LINE (it just includes my SQL connection user/pass) */
|
||||
include( $_SERVER['DOCUMENT_ROOT']."/datatables/mysql.php" );
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* If you just want to use the basic configuration for DataTables with PHP server-side, there is
|
||||
* no need to edit below this line
|
||||
*/
|
||||
|
||||
/*
|
||||
* MySQL connection
|
||||
*/
|
||||
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
|
||||
die( 'Could not open connection to server' );
|
||||
|
||||
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
|
||||
die( 'Could not select database '. $gaSql['db'] );
|
||||
|
||||
|
||||
/*
|
||||
* Paging
|
||||
*/
|
||||
$sLimit = "";
|
||||
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
|
||||
{
|
||||
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
|
||||
mysql_real_escape_string( $_GET['iDisplayLength'] );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Ordering
|
||||
*/
|
||||
$sOrder = "";
|
||||
if ( isset( $_GET['iSortCol_0'] ) )
|
||||
{
|
||||
$sOrder = "ORDER BY ";
|
||||
for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
|
||||
{
|
||||
if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
|
||||
{
|
||||
$sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
|
||||
".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", ";
|
||||
}
|
||||
}
|
||||
|
||||
$sOrder = substr_replace( $sOrder, "", -2 );
|
||||
if ( $sOrder == "ORDER BY" )
|
||||
{
|
||||
$sOrder = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Filtering
|
||||
* NOTE this does not match the built-in DataTables filtering which does it
|
||||
* word by word on any field. It's possible to do here, but concerned about efficiency
|
||||
* on very large tables, and MySQL's regex functionality is very limited
|
||||
*/
|
||||
$sWhere = "";
|
||||
if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
|
||||
{
|
||||
$sWhere = "WHERE (";
|
||||
for ( $i=0 ; $i<count($aColumns) ; $i++ )
|
||||
{
|
||||
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
|
||||
}
|
||||
$sWhere = substr_replace( $sWhere, "", -3 );
|
||||
$sWhere .= ')';
|
||||
}
|
||||
|
||||
/* Individual column filtering */
|
||||
for ( $i=0 ; $i<count($aColumns) ; $i++ )
|
||||
{
|
||||
if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
|
||||
{
|
||||
if ( $sWhere == "" )
|
||||
{
|
||||
$sWhere = "WHERE ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$sWhere .= " AND ";
|
||||
}
|
||||
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SQL queries
|
||||
* Get data to display
|
||||
*/
|
||||
$sQuery = "
|
||||
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
|
||||
FROM $sTable
|
||||
$sWhere
|
||||
$sOrder
|
||||
$sLimit
|
||||
";
|
||||
$rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
|
||||
|
||||
/* Data set length after filtering */
|
||||
$sQuery = "
|
||||
SELECT FOUND_ROWS()
|
||||
";
|
||||
$rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
|
||||
$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
|
||||
$iFilteredTotal = $aResultFilterTotal[0];
|
||||
|
||||
/* Total data set length */
|
||||
$sQuery = "
|
||||
SELECT COUNT(".$sIndexColumn.")
|
||||
FROM $sTable
|
||||
";
|
||||
$rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
|
||||
$aResultTotal = mysql_fetch_array($rResultTotal);
|
||||
$iTotal = $aResultTotal[0];
|
||||
|
||||
|
||||
/*
|
||||
* Output
|
||||
*/
|
||||
$output = array(
|
||||
"sEcho" => intval($_GET['sEcho']),
|
||||
"iTotalRecords" => $iTotal,
|
||||
"iTotalDisplayRecords" => $iFilteredTotal,
|
||||
"test" => array()
|
||||
);
|
||||
|
||||
while ( $aRow = mysql_fetch_array( $rResult ) )
|
||||
{
|
||||
$row = array();
|
||||
for ( $i=0 ; $i<count($aColumns) ; $i++ )
|
||||
{
|
||||
if ( $aColumns[$i] == "version" )
|
||||
{
|
||||
/* Special output formatting for 'version' column */
|
||||
$row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
|
||||
}
|
||||
else if ( $aColumns[$i] != ' ' )
|
||||
{
|
||||
/* General output */
|
||||
$row[] = $aRow[ $aColumns[$i] ];
|
||||
}
|
||||
}
|
||||
$output['test'][] = $row;
|
||||
}
|
||||
|
||||
echo json_encode( $output );
|
||||
?>
|
32
media/js/jquery.dataTables.js
vendored
32
media/js/jquery.dataTables.js
vendored
@ -1284,6 +1284,15 @@
|
||||
*/
|
||||
this.sAjaxSource = null;
|
||||
|
||||
/*
|
||||
* Variable: sAjaxDataProp
|
||||
* Purpose: Property from a given object from which to read the table data from. This can
|
||||
* be an empty string (when not server-side processing), in which case it is
|
||||
* assumed an an array is given directly.
|
||||
* Scope: jQuery.dataTable.classSettings
|
||||
*/
|
||||
this.sAjaxDataProp = 'aaData';
|
||||
|
||||
/*
|
||||
* Variable: bAjaxDataGet
|
||||
* Purpose: Note if draw should be blocked while getting data
|
||||
@ -2340,10 +2349,17 @@
|
||||
if ( oSettings.sAjaxSource !== null && !oSettings.oFeatures.bServerSide && !bDefer )
|
||||
{
|
||||
oSettings.fnServerData.call( oSettings.oInstance, oSettings.sAjaxSource, [], function(json) {
|
||||
/* Got the data - add it to the table */
|
||||
for ( i=0 ; i<json.aaData.length ; i++ )
|
||||
var aData = json;
|
||||
if ( oSettings.sAjaxDataProp != "" )
|
||||
{
|
||||
_fnAddData( oSettings, json.aaData[i] );
|
||||
var fnDataSrc = _fnGetObjectDataFn( oSettings.sAjaxDataProp );
|
||||
aData = fnDataSrc( json );
|
||||
}
|
||||
|
||||
/* Got the data - add it to the table */
|
||||
for ( i=0 ; i<aData.length ; i++ )
|
||||
{
|
||||
_fnAddData( oSettings, aData[i] );
|
||||
}
|
||||
|
||||
/* Reset the init display for cookie saving. We've already done a filter, and
|
||||
@ -3380,8 +3396,11 @@
|
||||
{
|
||||
var aiIndex = _fnReOrderIndex( oSettings, json.sColumns );
|
||||
}
|
||||
|
||||
var fnDataSrc = _fnGetObjectDataFn( oSettings.sAjaxDataProp );
|
||||
aData = fnDataSrc( json );
|
||||
|
||||
for ( var i=0, iLen=json.aaData.length ; i<iLen ; i++ )
|
||||
for ( var i=0, iLen=aData.length ; i<iLen ; i++ )
|
||||
{
|
||||
if ( bReOrder )
|
||||
{
|
||||
@ -3389,14 +3408,14 @@
|
||||
var aData = [];
|
||||
for ( var j=0, jLen=oSettings.aoColumns.length ; j<jLen ; j++ )
|
||||
{
|
||||
aData.push( json.aaData[i][ aiIndex[j] ] );
|
||||
aData.push( aData[i][ aiIndex[j] ] );
|
||||
}
|
||||
_fnAddData( oSettings, aData );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No re-order required, sever got it "right" - just straight add */
|
||||
_fnAddData( oSettings, json.aaData[i] );
|
||||
_fnAddData( oSettings, aData[i] );
|
||||
}
|
||||
}
|
||||
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
|
||||
@ -6718,6 +6737,7 @@
|
||||
_fnMap( oSettings, oInit, "aLengthMenu" );
|
||||
_fnMap( oSettings, oInit, "sPaginationType" );
|
||||
_fnMap( oSettings, oInit, "sAjaxSource" );
|
||||
_fnMap( oSettings, oInit, "sAjaxDataProp" );
|
||||
_fnMap( oSettings, oInit, "iCookieDuration" );
|
||||
_fnMap( oSettings, oInit, "sCookiePrefix" );
|
||||
_fnMap( oSettings, oInit, "sDom" );
|
||||
|
139
media/unit_testing/tests_onhold/3_ajax/sAjaxDataProp.js
Normal file
139
media/unit_testing/tests_onhold/3_ajax/sAjaxDataProp.js
Normal file
@ -0,0 +1,139 @@
|
||||
// DATA_TEMPLATE: empty_table
|
||||
oTest.fnStart( "Custom data source property - property given" );
|
||||
|
||||
|
||||
$(document).ready( function () {
|
||||
var oInit = {
|
||||
"sAjaxSource": "../../../examples/ajax/sources/custom_prop.txt",
|
||||
"sAjaxDataProp": "test"
|
||||
};
|
||||
$('#example').dataTable( oInit );
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"10 rows shown on the first page",
|
||||
null,
|
||||
function () { return $('#example tbody tr').length == 10; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Initial sort occured",
|
||||
null,
|
||||
function () { return $('#example tbody td:eq(0)').html() == "Gecko"; }
|
||||
);
|
||||
|
||||
/* Need to use the WaitTest for sorting due to the setTimeout datatables uses */
|
||||
oTest.fnTest(
|
||||
"Sorting (first click) on second column",
|
||||
function () { $('#example thead th:eq(1)').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "All others"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting (second click) on second column",
|
||||
function () { $('#example thead th:eq(1)').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting (third click) on second column",
|
||||
function () { $('#example thead th:eq(1)').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "All others"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting (first click) on numeric column",
|
||||
function () { $('#example thead th:eq(3)').click(); },
|
||||
function () { return $('#example tbody td:eq(3)').html() == "-"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting (second click) on numeric column",
|
||||
function () { $('#example thead th:eq(3)').click(); },
|
||||
function () { return $('#example tbody td:eq(3)').html() == "522.1"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting multi-column (first click)",
|
||||
function () {
|
||||
$('#example thead th:eq(0)').click();
|
||||
oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); },
|
||||
function () { var b =
|
||||
$('#example tbody td:eq(0)').html() == "Gecko" &&
|
||||
$('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting multi-column - sorting second column only",
|
||||
function () {
|
||||
$('#example thead th:eq(1)').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "All others"; }
|
||||
);
|
||||
|
||||
/* Basic paging */
|
||||
oTest.fnTest(
|
||||
"Paging to second page",
|
||||
function () { $('#example_next').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Paging to first page",
|
||||
function () { $('#example_previous').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "All others"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Attempting to page back beyond the first page",
|
||||
function () { $('#example_previous').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "All others"; }
|
||||
);
|
||||
|
||||
/* Changing length */
|
||||
oTest.fnTest(
|
||||
"Changing table length to 25 records",
|
||||
function () { $("select[name=example_length]").val('25').change(); },
|
||||
function () { return $('#example tbody tr').length == 25; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Changing table length to 50 records",
|
||||
function () { $("select[name=example_length]").val('50').change(); },
|
||||
function () { return $('#example tbody tr').length == 50; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Changing table length to 100 records",
|
||||
function () { $("select[name=example_length]").val('100').change(); },
|
||||
function () { return $('#example tbody tr').length == 57; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Changing table length to 10 records",
|
||||
function () { $("select[name=example_length]").val('10').change(); },
|
||||
function () { return $('#example tbody tr').length == 10; }
|
||||
);
|
||||
|
||||
/*
|
||||
* Information element
|
||||
*/
|
||||
oTest.fnTest(
|
||||
"Information on zero config",
|
||||
null,
|
||||
function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Information on second page",
|
||||
function () { $('#example_next').click(); },
|
||||
function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Information on third page",
|
||||
function () { $('#example_next').click(); },
|
||||
function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; }
|
||||
);
|
||||
|
||||
|
||||
oTest.fnComplete();
|
||||
} );
|
139
media/unit_testing/tests_onhold/3_ajax/sAjaxDataProp2.js
Normal file
139
media/unit_testing/tests_onhold/3_ajax/sAjaxDataProp2.js
Normal file
@ -0,0 +1,139 @@
|
||||
// DATA_TEMPLATE: empty_table
|
||||
oTest.fnStart( "Custom data source property - array only" );
|
||||
|
||||
|
||||
$(document).ready( function () {
|
||||
var oInit = {
|
||||
"sAjaxSource": "../../../examples/ajax/sources/array_only.txt",
|
||||
"sAjaxDataProp": ""
|
||||
};
|
||||
$('#example').dataTable( oInit );
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"10 rows shown on the first page",
|
||||
null,
|
||||
function () { return $('#example tbody tr').length == 10; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Initial sort occured",
|
||||
null,
|
||||
function () { return $('#example tbody td:eq(0)').html() == "Gecko"; }
|
||||
);
|
||||
|
||||
/* Need to use the WaitTest for sorting due to the setTimeout datatables uses */
|
||||
oTest.fnTest(
|
||||
"Sorting (first click) on second column",
|
||||
function () { $('#example thead th:eq(1)').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "All others"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting (second click) on second column",
|
||||
function () { $('#example thead th:eq(1)').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting (third click) on second column",
|
||||
function () { $('#example thead th:eq(1)').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "All others"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting (first click) on numeric column",
|
||||
function () { $('#example thead th:eq(3)').click(); },
|
||||
function () { return $('#example tbody td:eq(3)').html() == "-"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting (second click) on numeric column",
|
||||
function () { $('#example thead th:eq(3)').click(); },
|
||||
function () { return $('#example tbody td:eq(3)').html() == "522.1"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting multi-column (first click)",
|
||||
function () {
|
||||
$('#example thead th:eq(0)').click();
|
||||
oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); },
|
||||
function () { var b =
|
||||
$('#example tbody td:eq(0)').html() == "Gecko" &&
|
||||
$('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Sorting multi-column - sorting second column only",
|
||||
function () {
|
||||
$('#example thead th:eq(1)').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "All others"; }
|
||||
);
|
||||
|
||||
/* Basic paging */
|
||||
oTest.fnTest(
|
||||
"Paging to second page",
|
||||
function () { $('#example_next').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "IE Mobile"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Paging to first page",
|
||||
function () { $('#example_previous').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "All others"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Attempting to page back beyond the first page",
|
||||
function () { $('#example_previous').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "All others"; }
|
||||
);
|
||||
|
||||
/* Changing length */
|
||||
oTest.fnTest(
|
||||
"Changing table length to 25 records",
|
||||
function () { $("select[name=example_length]").val('25').change(); },
|
||||
function () { return $('#example tbody tr').length == 25; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Changing table length to 50 records",
|
||||
function () { $("select[name=example_length]").val('50').change(); },
|
||||
function () { return $('#example tbody tr').length == 50; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Changing table length to 100 records",
|
||||
function () { $("select[name=example_length]").val('100').change(); },
|
||||
function () { return $('#example tbody tr').length == 57; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Changing table length to 10 records",
|
||||
function () { $("select[name=example_length]").val('10').change(); },
|
||||
function () { return $('#example tbody tr').length == 10; }
|
||||
);
|
||||
|
||||
/*
|
||||
* Information element
|
||||
*/
|
||||
oTest.fnTest(
|
||||
"Information on zero config",
|
||||
null,
|
||||
function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Information on second page",
|
||||
function () { $('#example_next').click(); },
|
||||
function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; }
|
||||
);
|
||||
|
||||
oTest.fnTest(
|
||||
"Information on third page",
|
||||
function () { $('#example_next').click(); },
|
||||
function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; }
|
||||
);
|
||||
|
||||
|
||||
oTest.fnComplete();
|
||||
} );
|
146
media/unit_testing/tests_onhold/4_server-side/sAjaxDataProp.js
Normal file
146
media/unit_testing/tests_onhold/4_server-side/sAjaxDataProp.js
Normal file
@ -0,0 +1,146 @@
|
||||
// DATA_TEMPLATE: empty_table
|
||||
/*
|
||||
* NOTE: There are some differences in this zero config script for server-side
|
||||
* processing compared to the other data sources. The main reason for this is the
|
||||
* difference in how the server-side processing does it's filtering. Also the
|
||||
* sorting state is always reset on each draw.
|
||||
*/
|
||||
oTest.fnStart( "Custom data property in returned Ajax" );
|
||||
|
||||
$(document).ready( function () {
|
||||
$('#example').dataTable( {
|
||||
"bServerSide": true,
|
||||
"sAjaxSource": "../../../examples/server_side/scripts/custom_data_property.php",
|
||||
"sAjaxDataProp": "test"
|
||||
} );
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"10 rows shown on the first page",
|
||||
null,
|
||||
function () { return $('#example tbody tr').length == 10; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Initial sort occured",
|
||||
null,
|
||||
function () { return $('#example tbody td:eq(0)').html() == "Gecko"; }
|
||||
);
|
||||
|
||||
/* Need to use the WaitTest for sorting due to the setTimeout datatables uses */
|
||||
oTest.fnWaitTest(
|
||||
"Sorting (first click) on second column",
|
||||
function () { $('#example thead th:eq(1)').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "All others"; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Sorting (second click) on second column",
|
||||
function () { $('#example thead th:eq(1)').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "Seamonkey 1.1"; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Sorting (third click) on second column",
|
||||
function () { $('#example thead th:eq(1)').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "All others"; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Sorting (first click) on numeric column",
|
||||
function () { $('#example thead th:eq(3)').click(); },
|
||||
function () { return $('#example tbody td:eq(3)').html() == "-"; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Sorting (second click) on numeric column",
|
||||
function () { $('#example thead th:eq(3)').click(); },
|
||||
function () { return $('#example tbody td:eq(3)').html() == "522.1"; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Sorting multi-column (first click)",
|
||||
function () {
|
||||
$('#example thead th:eq(0)').click();
|
||||
oDispacher.click( $('#example thead th:eq(1)')[0], { 'shift': true } ); },
|
||||
function () { var b =
|
||||
$('#example tbody td:eq(0)').html() == "Gecko" &&
|
||||
$('#example tbody td:eq(1)').html() == "Camino 1.0"; return b; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Sorting multi-column - sorting first column only",
|
||||
function () {
|
||||
$('#example thead th:eq(0)').click(); },
|
||||
function () { var b =
|
||||
$('#example tbody td:eq(0)').html() == "Gecko" &&
|
||||
$('#example tbody td:eq(1)').html() == "Firefox 1.0"; return b; }
|
||||
);
|
||||
|
||||
/* Basic paging */
|
||||
oTest.fnWaitTest(
|
||||
"Paging to second page",
|
||||
function () { $('#example_next').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "Mozilla 1.1"; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Paging to first page",
|
||||
function () { $('#example_previous').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "Firefox 1.0"; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Attempting to page back beyond the first page",
|
||||
function () { $('#example_previous').click(); },
|
||||
function () { return $('#example tbody td:eq(1)').html() == "Firefox 1.0"; }
|
||||
);
|
||||
|
||||
/* Changing length */
|
||||
oTest.fnWaitTest(
|
||||
"Changing table length to 25 records",
|
||||
function () { $("select[name=example_length]").val('25').change(); },
|
||||
function () { return $('#example tbody tr').length == 25; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Changing table length to 50 records",
|
||||
function () { $("select[name=example_length]").val('50').change(); },
|
||||
function () { return $('#example tbody tr').length == 50; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Changing table length to 100 records",
|
||||
function () { $("select[name=example_length]").val('100').change(); },
|
||||
function () { return $('#example tbody tr').length == 57; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Changing table length to 10 records",
|
||||
function () { $("select[name=example_length]").val('10').change(); },
|
||||
function () { return $('#example tbody tr').length == 10; }
|
||||
);
|
||||
|
||||
/*
|
||||
* Information element
|
||||
*/
|
||||
oTest.fnWaitTest(
|
||||
"Information on zero config",
|
||||
null,
|
||||
function () { return document.getElementById('example_info').innerHTML == "Showing 1 to 10 of 57 entries"; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Information on second page",
|
||||
function () { $('#example_next').click(); },
|
||||
function () { return document.getElementById('example_info').innerHTML == "Showing 11 to 20 of 57 entries"; }
|
||||
);
|
||||
|
||||
oTest.fnWaitTest(
|
||||
"Information on third page",
|
||||
function () { $('#example_next').click(); },
|
||||
function () { return document.getElementById('example_info').innerHTML == "Showing 21 to 30 of 57 entries"; }
|
||||
);
|
||||
|
||||
|
||||
oTest.fnComplete();
|
||||
} );
|
Loading…
x
Reference in New Issue
Block a user