1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-01-18 11:52:11 +01:00

Update: Provide link to technical note explaining errors for DT logged

errors

- A lot of posts in the forum are questions such as "what does the
  invalid JSON response" error mean, or "how to fix the unknown
  requested parameter error". To address these, rather than having them
  answered individually in the forum, I'm going to write a series of
  technical notes for DataTables (getting started, how to use columns
  etc) and as part of those, each error that DataTables can fire off
  will have a technical note explaining in deatil what the error means.

- Example:
   DataTables warning: table id=example - Invalid JSON response. For
   more information about this error, please see
   http://datatables.net/tn/1

- This commit puts the required logic in place. The technical notes
  don't exist yet, but they will soon. They will be:

1 - Invalid JSON response
2 - Non-table node initialisation ({this.nodeName})
3 - Cannot reinitialise DataTable
4 - Requested unknown parameter {param} for row {idx}
5 - Unknown paging action: {action}
6 - Possible column misalignment
		- The table cannot fit into the current element which
		  will cause column

- This also has the advantage that the errors in the DataTables code can
  be a little smaller. Around 500 bytes saved.

- This fixes issue #173
This commit is contained in:
Allan Jardine 2013-05-26 09:15:21 +01:00
parent 1b8f4608ac
commit 7f1dfc2b38
6 changed files with 39 additions and 52 deletions

View File

@ -59,7 +59,7 @@ function _fnBuildAjax( oSettings, data, fn )
"type": oSettings.sServerMethod,
"error": function (xhr, error, thrown) {
if ( error == "parsererror" ) {
oSettings.oApi._fnLog( oSettings, 0, "DataTables: invalid JSON response" );
oSettings.oApi._fnLog( oSettings, 0, 'Invalid JSON response', 1 );
}
}
};

View File

@ -9,8 +9,7 @@ var oInitEmpty = oInit === undefined ? true : false;
/* Sanity check */
if ( this.nodeName.toLowerCase() != 'table' )
{
_fnLog( null, 0, "Attempted to initialise DataTables on a node which is not a "+
"table: "+this.nodeName );
_fnLog( null, 0, 'Non-table node initialisation ('+this.nodeName+')', 2 );
return;
}
@ -45,9 +44,7 @@ for ( i=0, iLen=DataTable.settings.length ; i<iLen ; i++ )
}
else
{
_fnLog( DataTable.settings[i], 0, "Cannot reinitialise DataTable.\n\n"+
"To retrieve the DataTables object for this table, pass no arguments or see "+
"the docs for bRetrieve and bDestroy" );
_fnLog( DataTable.settings[i], 0, 'Cannot reinitialise DataTable', 3 );
return;
}
}

View File

@ -159,8 +159,8 @@ function _fnGetCellData( oSettings, iRow, iCol, sSpecific )
if ( oSettings.iDrawError != oSettings.iDraw && oCol.sDefaultContent === null )
{
_fnLog( oSettings, 0, "Requested unknown parameter "+
(typeof oCol.mData=='function' ? '{mData function}' : "'"+oCol.mData+"'")+
" from the data source for row "+iRow );
(typeof oCol.mData=='function' ? '{function}' : "'"+oCol.mData+"'")+
" for row "+iRow, 4 );
oSettings.iDrawError = oSettings.iDraw;
}
return oCol.sDefaultContent;

View File

@ -99,7 +99,7 @@ function _fnPageChange ( settings, action )
}
else
{
_fnLog( settings, 0, "Unknown paging action: "+action );
_fnLog( settings, 0, "Unknown paging action: "+action, 5 );
}
var changed = settings._iDisplayStart !== start;

View File

@ -392,16 +392,9 @@ function _fnScrollDraw ( o )
}
/* And give the user a warning that we've stopped the table getting too small */
if ( o.oScroll.sX === "" )
if ( o.oScroll.sX === "" || o.oScroll.sXInner !== "" )
{
_fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
" misalignment. The table has been drawn at its minimum possible width." );
}
else if ( o.oScroll.sXInner !== "" )
{
_fnLog( o, 1, "The table cannot fit into the current element which will cause column"+
" misalignment. Increase the sScrollXInner value or remove it to allow automatic"+
" calculation" );
_fnLog( o, 1, 'Possible column misalignment', 6 );
}
}
else

View File

@ -1,52 +1,49 @@
/**
* Return the settings object for a particular table
* @param {node} nTable table we are using as a dataTable
* @param {node} table table we are using as a dataTable
* @returns {object} Settings object - or null if not found
* @memberof DataTable#oApi
*/
function _fnSettingsFromNode ( nTable )
function _fnSettingsFromNode ( table )
{
for ( var i=0 ; i<DataTable.settings.length ; i++ )
{
if ( DataTable.settings[i].nTable === nTable )
{
return DataTable.settings[i];
}
}
var settings = DataTable.settings;
var idx = $.inArray( table, _pluck( settings, 'nTable' ) );
return null;
return idx !== -1 ?
settings[ idx ] :
null;
}
/**
* Log an error message
* @param {object} oSettings dataTables settings object
* @param {int} iLevel log error messages, or display them to the user
* @param {string} sMesg error message
* @param {object} settings dataTables settings object
* @param {int} level log error messages, or display them to the user
* @param {string} msg error message
* @param {int} tn Technical note id to get more information about the error.
* @memberof DataTable#oApi
*/
function _fnLog( oSettings, iLevel, sMesg )
function _fnLog( settings, level, msg, tn )
{
var sAlert = (oSettings===null) ?
"DataTables warning: "+sMesg :
"DataTables warning (table id = '"+oSettings.sTableId+"'): "+sMesg;
msg = 'DataTables warning: '+
(settings!==null ? 'table id='+settings.sTableId+' - ' : '')+msg;
if ( iLevel === 0 )
{
if ( DataTable.ext.sErrMode == 'alert' )
{
alert( sAlert );
if ( tn ) {
msg += '. For more information about this error, please see '+
'http://datatables.net/tn/'+tn;
}
else
{
throw new Error(sAlert);
if ( ! level ) {
if ( DataTable.ext.sErrMode == 'alert' ) {
alert( msg );
}
return;
else {
throw new Error(msg);
}
else if ( window.console && console.log )
{
console.log( sAlert );
}
else if ( window.console && console.log ) {
console.log( msg );
}
}