Also correct a load of JS errors such as leaking variables and use consistent formatting.pull/40/head
parent
0ab60d10ee
commit
4f29d7fda6
@ -1,18 +1,19 @@
|
|||||||
/**
|
/**
|
||||||
* Update the internal data for a TR element based on what is used in the
|
* Update the internal data for a TR element based on what is used in the
|
||||||
* DOM. You will likely want to call fnDraw() after this function.
|
* DOM. You will likely want to call fnDraw() after this function.
|
||||||
|
*
|
||||||
* @name fnDataUpdate
|
* @name fnDataUpdate
|
||||||
* @anchor fnDataUpdate
|
* @summary
|
||||||
* @author Lior Gerson
|
* @author Lior Gerson
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$.fn.dataTableExt.oApi.fnDataUpdate = function ( oSettings, nRowObject, iRowIndex )
|
jQuery.fn.dataTableExt.oApi.fnDataUpdate = function ( oSettings, nRowObject, iRowIndex )
|
||||||
{
|
{
|
||||||
$(nRowObject).find("TD").each( function(i) {
|
jQuery(nRowObject).find("TD").each( function(i) {
|
||||||
var iColIndex = oSettings.oApi._fnVisibleToColumnIndex( oSettings, i );
|
var iColIndex = oSettings.oApi._fnVisibleToColumnIndex( oSettings, i );
|
||||||
oSettings.oApi._fnSetCellData( oSettings, iRowIndex, iColIndex, $(this).html() );
|
oSettings.oApi._fnSetCellData( oSettings, iRowIndex, iColIndex, jQuery(this).html() );
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* Jump to data
|
||||||
|
*
|
||||||
|
* @name page.JumpToData()
|
||||||
|
* @summary
|
||||||
|
* @author [Allan Jardine](http://sprymedia.co.uk)
|
||||||
|
* @requires DataTables 1.10+
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* table.page.jumpToData( 0, "Allan Jardine" );
|
||||||
|
*/
|
||||||
|
|
||||||
|
jQuery.fn.dataTable.Api.register( 'page.jumpToData()', function ( column, data ) {
|
||||||
|
var pos = this.column(column, {order:'current'}).data().indexOf( data );
|
||||||
|
|
||||||
|
if ( pos >= 0 ) {
|
||||||
|
var page = Math.floor( pos / this.page.info().length );
|
||||||
|
this.page( page ).draw( false );
|
||||||
|
}
|
||||||
|
} );
|
@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* When search a table with accented characters, it can be frustrating to have
|
||||||
|
* an input such as _Zurich_ not match _Zürich_ in the table (`u !== ü`). This
|
||||||
|
* type based search plug-in replaces the built-in string formatter in
|
||||||
|
* DataTables with a function that will remove replace the accented characters
|
||||||
|
* with their unaccented counterparts for fast and easy filtering.
|
||||||
|
*
|
||||||
|
* Note that with the accented characters being replaced, a search input using
|
||||||
|
* accented characters will no longer match. The second example below shows
|
||||||
|
* how the function can be used to remove accents from the search input as well,
|
||||||
|
* to mitigate this problem.
|
||||||
|
*
|
||||||
|
* @summary Replace accented characters with unaccented counterparts
|
||||||
|
* @name Accent neutralise
|
||||||
|
* @author Allan Jardine
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $(document).ready(function() {
|
||||||
|
* $('#example').dataTable();
|
||||||
|
* } );
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $(document).ready(function() {
|
||||||
|
* var table = $('#example').dataTable();
|
||||||
|
*
|
||||||
|
* // Remove accented character from search input as well
|
||||||
|
* $('#myInput').keyup( function () {
|
||||||
|
* table
|
||||||
|
* .search(
|
||||||
|
* jQuery.fn.DataTable.ext.type.search.string( this )
|
||||||
|
* )
|
||||||
|
* .draw()
|
||||||
|
* } );
|
||||||
|
* } );
|
||||||
|
*/
|
||||||
|
|
||||||
|
jQuery.fn.DataTable.ext.type.search.string = function ( data ) {
|
||||||
|
return ! data ?
|
||||||
|
'' :
|
||||||
|
typeof data === 'string' ?
|
||||||
|
data
|
||||||
|
.replace( /\n/g, ' ' )
|
||||||
|
.replace( /á/g, 'a' )
|
||||||
|
.replace( /é/g, 'e' )
|
||||||
|
.replace( /í/g, 'i' )
|
||||||
|
.replace( /ó/g, 'o' )
|
||||||
|
.replace( /ú/g, 'u' )
|
||||||
|
.replace( /ê/g, 'e' )
|
||||||
|
.replace( /î/g, 'i' )
|
||||||
|
.replace( /ô/g, 'o' )
|
||||||
|
.replace( /è/g, 'e' )
|
||||||
|
.replace( /ï/g, 'i' )
|
||||||
|
.replace( /ü/g, 'u' )
|
||||||
|
.replace( /ç/g, 'c' ) :
|
||||||
|
data;
|
||||||
|
};
|
@ -1,32 +1,38 @@
|
|||||||
/**
|
/**
|
||||||
* DataTables has a built in type called 'html' which will strip HTML tags
|
* DataTables has a built in type called `html` which will strip HTML tags
|
||||||
* from a search string, but it doesn't cope with nested HTML inside another
|
* from a search string, but it doesn't cope with nested HTML inside another
|
||||||
* element's attributes (for example DOM0 events with have HTML in them). This
|
* element's attributes (for example DOM0 events with have HTML in them). This
|
||||||
* plug-in function overrules the built-in method and provides complete HTML
|
* plug-in function overrules the built-in method and provides complete HTML
|
||||||
* tag removal. Note that this function is not included in DataTables by
|
* tag removal.
|
||||||
|
*
|
||||||
|
* Note that this function is not included in DataTables by
|
||||||
* default because it is slightly slower than the built-in method, which is
|
* default because it is slightly slower than the built-in method, which is
|
||||||
* good enough for by far the majority of use cases.
|
* good enough for by far the majority of use cases.
|
||||||
|
*
|
||||||
|
* @summary Strip HTML using DOM methods
|
||||||
* @name html
|
* @name html
|
||||||
* @anchor html_column
|
* @author _guillimon_
|
||||||
* @author <i>guillimon</i>
|
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* $(document).ready(function() {
|
* $(document).ready(function() {
|
||||||
* var oTable = $('#example').dataTable({
|
* $('#example').dataTable({
|
||||||
* "aoColumns": [
|
* "columnDefs": [
|
||||||
* "sType": "html",
|
* { type: "html", target: 0 }
|
||||||
* null
|
|
||||||
* ]
|
* ]
|
||||||
* });
|
* });
|
||||||
* } );
|
* } );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
jQuery.fn.dataTableExt.ofnSearch['html'] = function ( sData ) {
|
(function () {
|
||||||
var n = document.createElement('div');
|
|
||||||
n.innerHTML = sData;
|
var _div = document.createElement('div');
|
||||||
if ( n.textContent ) {
|
|
||||||
return n.textContent.replace(/\n/g," ");
|
jQuery.fn.dataTable.ext.type.search.html = function ( data ) {
|
||||||
} else {
|
_div.innerHTML = data;
|
||||||
return n.innerText.replace(/\n/g," ");
|
|
||||||
}
|
return _div.textContent ?
|
||||||
|
_div.textContent.replace(/\n/g," ") :
|
||||||
|
_div.innerText.replace(/\n/g," ");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
})();
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
* Telephone numbers are a common data point to display in HTML tables, and are
|
||||||
|
* often formatted (e.g. `dt-string 555-1234`). Typically, when searching a
|
||||||
|
* table a user would need to enter the number in exactly the same format it is
|
||||||
|
* displayed in, but this is not always convenient (e.g. you might search for
|
||||||
|
* `dt-string 5551`).
|
||||||
|
*
|
||||||
|
* This filtering plug-in will allow both forms to be matched be providing both
|
||||||
|
* the formatted and de-formatted data to the table's search.
|
||||||
|
*
|
||||||
|
* @summary Make phone numbers searchable formatted or unformatted
|
||||||
|
* @name Phone number
|
||||||
|
* @author Allan Jardine
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $(document).ready(function() {
|
||||||
|
* $('#example').dataTable( {
|
||||||
|
* columnDefs: [
|
||||||
|
* { type: 'phoneNumber', target: 4 }
|
||||||
|
* ]
|
||||||
|
* } );
|
||||||
|
* } );
|
||||||
|
*/
|
||||||
|
|
||||||
|
jQuery.fn.DataTable.ext.type.search.phoneNumber = function ( data ) {
|
||||||
|
return ! data ?
|
||||||
|
'' :
|
||||||
|
typeof data === 'string' ?
|
||||||
|
data + data.replace(/[ \-]/g, '') :
|
||||||
|
data;
|
||||||
|
};
|
@ -1,15 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Read information from a column of checkboxes (input elements with type
|
* Read information from a column of checkboxes (input elements with type
|
||||||
* checkbox) and return an array to use as a basis for sorting.
|
* checkbox) and return an array to use as a basis for sorting.
|
||||||
|
*
|
||||||
|
* @summary Sort based on the checked state of checkboxes in a column
|
||||||
* @name Checkbox data source
|
* @name Checkbox data source
|
||||||
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>
|
* @author [Allan Jardine](http://sprymedia.co.uk)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function ( oSettings, iColumn )
|
$.fn.dataTable.ext.order['dom-checkbox'] = function ( settings, col )
|
||||||
{
|
{
|
||||||
var aData = [];
|
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
|
||||||
$( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
|
return $('input', td).prop('checked') ? '1' : '0';
|
||||||
aData.push( this.checked==true ? "1" : "0" );
|
|
||||||
} );
|
} );
|
||||||
return aData;
|
|
||||||
};
|
};
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
/**
|
/**
|
||||||
* Read information from a column of select (drop down) menus and return an
|
* Read information from a column of select (drop down) menus and return an
|
||||||
* array to use as a basis for sorting.
|
* array to use as a basis for sorting.
|
||||||
|
*
|
||||||
|
* @summary Sort based on the value of the `dt-tag select` options in a column
|
||||||
* @name Select menu data source
|
* @name Select menu data source
|
||||||
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>
|
* @requires DataTables 1.10+
|
||||||
|
* @author [Allan Jardine](http://sprymedia.co.uk)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$.fn.dataTableExt.afnSortData['dom-select'] = function ( oSettings, iColumn )
|
$.fn.dataTable.ext.order['dom-select'] = function ( settings, col )
|
||||||
{
|
{
|
||||||
var aData = [];
|
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
|
||||||
$( 'td:eq('+iColumn+') select', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
|
return $('select', td).val();
|
||||||
aData.push( $(this).val() );
|
|
||||||
} );
|
} );
|
||||||
return aData;
|
|
||||||
};
|
};
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
/**
|
/**
|
||||||
* Read information from a column of input (type text) elements and return an
|
* Read information from a column of input (type text) elements and return an
|
||||||
* array to use as a basis for sorting.
|
* array to use as a basis for sorting.
|
||||||
|
*
|
||||||
|
* @summary Sorting based on the values of `dt-tag input` elements in a column.
|
||||||
* @name Input element data source
|
* @name Input element data source
|
||||||
* @author <a href="http://sprymedia.co.uk">Allan Jardine</a>
|
* @requires DataTables 1.10+
|
||||||
|
* @author [Allan Jardine](http://sprymedia.co.uk)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$.fn.dataTableExt.afnSortData['dom-text'] = function ( oSettings, iColumn )
|
$.fn.dataTable.ext.order['dom-text'] = function ( settings, col )
|
||||||
{
|
{
|
||||||
var aData = [];
|
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
|
||||||
$( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
|
return $('input', td).val();
|
||||||
aData.push( this.value );
|
|
||||||
} );
|
} );
|
||||||
return aData;
|
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
/**
|
||||||
|
* This sorting plug-in for DataTables will correctly sort data in date time
|
||||||
|
* format typically used in Germany - `dd.mm.YYYY HH:mm`.
|
||||||
|
*
|
||||||
|
* @name Date / time (dd.mm.YYYY HH:mm)
|
||||||
|
* @summary Sort date / time in the format `dd.mm.YYYY HH:mm`.
|
||||||
|
* @author [Ronny Vedrilla](http://www.ambient-innovation.com)
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* $('#example').dataTable( {
|
||||||
|
* columnDefs: [
|
||||||
|
* { type: 'de_datetime', targets: 0 }
|
||||||
|
* ]
|
||||||
|
* } );
|
||||||
|
*/
|
||||||
|
|
||||||
|
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
|
||||||
|
"de_datetime-asc": function ( a, b ) {
|
||||||
|
var x, y;
|
||||||
|
if ($.trim(a) !== '') {
|
||||||
|
var deDatea = $.trim(a).split(' ');
|
||||||
|
var deTimea = deDatea[1].split(':');
|
||||||
|
var deDatea2 = deDatea[0].split('.');
|
||||||
|
x = (deDatea2[2] + deDatea2[1] + deDatea2[0] + deTimea[0] + deTimea[1]) * 1;
|
||||||
|
} else {
|
||||||
|
x = Infinity; // = l'an 1000 ...
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($.trim(b) !== '') {
|
||||||
|
var deDateb = $.trim(b).split(' ');
|
||||||
|
var deTimeb = deDateb[1].split(':');
|
||||||
|
deDateb = deDateb[0].split('.');
|
||||||
|
y = (deDateb[2] + deDateb[1] + deDateb[0] + deTimeb[0] + deTimeb[1]) * 1;
|
||||||
|
} else {
|
||||||
|
y = Infinity;
|
||||||
|
}
|
||||||
|
var z = ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
||||||
|
return z;
|
||||||
|
},
|
||||||
|
|
||||||
|
"de_datetime-desc": function ( a, b ) {
|
||||||
|
var x, y;
|
||||||
|
if ($.trim(a) !== '') {
|
||||||
|
var deDatea = $.trim(a).split(' ');
|
||||||
|
var deTimea = deDatea[1].split(':');
|
||||||
|
var deDatea2 = deDatea[0].split('.');
|
||||||
|
x = (deDatea2[2] + deDatea2[1] + deDatea2[0] + deTimea[0] + deTimea[1]) * 1;
|
||||||
|
} else {
|
||||||
|
x = Infinity;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($.trim(b) !== '') {
|
||||||
|
var deDateb = $.trim(b).split(' ');
|
||||||
|
var deTimeb = deDateb[1].split(':');
|
||||||
|
deDateb = deDateb[0].split('.');
|
||||||
|
y = (deDateb[2] + deDateb[1] + deDateb[0] + deTimeb[0] + deTimeb[1]) * 1;
|
||||||
|
} else {
|
||||||
|
y = Infinity;
|
||||||
|
}
|
||||||
|
var z = ((x < y) ? 1 : ((x > y) ? -1 : 0));
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
@ -1,59 +1,81 @@
|
|||||||
/*
|
/*
|
||||||
* Adds a new sorting option to dataTables called <code>datetime-us</code>. Also
|
* Adds a new sorting option to dataTables called `datetime-us`.
|
||||||
* includes a type detection plug-in. Matches and sorts date / time strings in
|
*
|
||||||
* the format: <code>(m)m/(d)d/(yy)yy (h)h/m(m) (am|pm)</code>. For example:
|
* Also included is a type detection plug-in. Matches and sorts date / time
|
||||||
* <ul>
|
* strings in the format: `(m)m/(d)d/(yy)yy (h)h/m(m) (am|pm)`. For example:
|
||||||
* <li>1/1/13 1:4 pm</li>
|
*
|
||||||
* <li>01/01/2013 01:04 PM</li>
|
* * 1/1/13 1:4 pm
|
||||||
* <li>1/1/2013 1:04 Pm</li>
|
* * 01/01/2013 01:04 PM
|
||||||
* </ul>
|
* * 1/1/2013 1:04 Pm
|
||||||
*
|
*
|
||||||
* @name Date / time - US
|
* @name Date / time - US
|
||||||
* @anchor datetime_us
|
* @summary Sort date / time in the format `m/d/yy h:m am|pm`
|
||||||
* @author <a href="http://mrkmg.com/">Kevin Gravier</a>
|
* @author [Kevin Gravier](http://mrkmg.com/)
|
||||||
*/
|
*
|
||||||
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
|
* @example
|
||||||
"datetime-us-pre": function ( a ) {
|
* $('#example').dataTable( {
|
||||||
var b = a.match(/(\d{1,2})\/(\d{1,2})\/(\d{2,4}) (\d{1,2}):(\d{1,2}) (am|pm|AM|PM|Am|Pm)/),
|
* columnDefs: [
|
||||||
month = b[1],
|
* { type: 'datetime-us', targets: 0 }
|
||||||
day = b[2],
|
* ]
|
||||||
year = b[3],
|
* } );
|
||||||
hour = b[4],
|
*/
|
||||||
min = b[5],
|
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
|
||||||
ap = b[6];
|
"datetime-us-pre": function (a) {
|
||||||
|
var b = a.match(/(\d{1,2})\/(\d{1,2})\/(\d{2,4}) (\d{1,2}):(\d{1,2}) (am|pm|AM|PM|Am|Pm)/),
|
||||||
|
month = b[1],
|
||||||
|
day = b[2],
|
||||||
|
year = b[3],
|
||||||
|
hour = b[4],
|
||||||
|
min = b[5],
|
||||||
|
ap = b[6];
|
||||||
|
|
||||||
|
if (hour == '12') {
|
||||||
|
hour = '0';
|
||||||
|
if (ap == 'pm') {
|
||||||
|
hour = parseInt(hour, 10) + 12;
|
||||||
|
}
|
||||||
|
|
||||||
if(hour == '12') hour = '0';
|
if (year.length == 2) {
|
||||||
if(ap == 'pm') hour = parseInt(hour, 10)+12;
|
if (parseInt(year, 10) < 70) {
|
||||||
|
year = '20' + year;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
year = '19' + year;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (month.length == 1) {
|
||||||
|
month = '0' + month;
|
||||||
|
}
|
||||||
|
if (day.length == 1) {
|
||||||
|
day = '0' + day;
|
||||||
|
}
|
||||||
|
if (hour.length == 1) {
|
||||||
|
hour = '0' + hour;
|
||||||
|
}
|
||||||
|
if (min.length == 1) {
|
||||||
|
min = '0' + min;
|
||||||
|
}
|
||||||
|
|
||||||
if(year.length == 2){
|
var tt = year + month + day + hour + min;
|
||||||
if(parseInt(year, 10)<70) year = '20'+year;
|
return tt;
|
||||||
else year = '19'+year;
|
}
|
||||||
}
|
},
|
||||||
if(month.length == 1) month = '0'+month;
|
|
||||||
if(day.length == 1) day = '0'+day;
|
|
||||||
if(hour.length == 1) hour = '0'+hour;
|
|
||||||
if(min.length == 1) min = '0'+min;
|
|
||||||
|
|
||||||
var tt = year+month+day+hour+min;
|
"datetime-us-asc": function (a, b) {
|
||||||
return tt;
|
return a - b;
|
||||||
},
|
},
|
||||||
"datetime-us-asc": function ( a, b ) {
|
|
||||||
return a - b;
|
|
||||||
},
|
|
||||||
|
|
||||||
"datetime-us-desc": function ( a, b ) {
|
"datetime-us-desc": function (a, b) {
|
||||||
return b - a;
|
return b - a;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
jQuery.fn.dataTableExt.aTypes.unshift(
|
jQuery.fn.dataTableExt.aTypes.unshift(
|
||||||
function ( sData )
|
function (sData) {
|
||||||
{
|
if (sData !== null && sData.match(/\d{1,2}\/\d{1,2}\/\d{2,4} \d{1,2}:\d{1,2} (am|pm|AM|PM|Am|Pm)/)) {
|
||||||
if (sData !== null && sData.match(/\d{1,2}\/\d{1,2}\/\d{2,4} \d{1,2}:\d{1,2} (am|pm|AM|PM|Am|Pm)/))
|
|
||||||
{
|
|
||||||
|
|
||||||
return 'datetime-us';
|
return 'datetime-us';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in new issue