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
|
||||
* DOM. You will likely want to call fnDraw() after this function.
|
||||
*
|
||||
* @name fnDataUpdate
|
||||
* @anchor fnDataUpdate
|
||||
* @summary
|
||||
* @author Lior Gerson
|
||||
*
|
||||
* @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 );
|
||||
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
|
||||
* 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
|
||||
* 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
|
||||
* good enough for by far the majority of use cases.
|
||||
*
|
||||
* @summary Strip HTML using DOM methods
|
||||
* @name html
|
||||
* @anchor html_column
|
||||
* @author <i>guillimon</i>
|
||||
* @author _guillimon_
|
||||
*
|
||||
* @example
|
||||
* $(document).ready(function() {
|
||||
* var oTable = $('#example').dataTable({
|
||||
* "aoColumns": [
|
||||
* "sType": "html",
|
||||
* null
|
||||
* $('#example').dataTable({
|
||||
* "columnDefs": [
|
||||
* { type: "html", target: 0 }
|
||||
* ]
|
||||
* });
|
||||
* } );
|
||||
*/
|
||||
|
||||
jQuery.fn.dataTableExt.ofnSearch['html'] = function ( sData ) {
|
||||
var n = document.createElement('div');
|
||||
n.innerHTML = sData;
|
||||
if ( n.textContent ) {
|
||||
return n.textContent.replace(/\n/g," ");
|
||||
} else {
|
||||
return n.innerText.replace(/\n/g," ");
|
||||
}
|
||||
(function () {
|
||||
|
||||
var _div = document.createElement('div');
|
||||
|
||||
jQuery.fn.dataTable.ext.type.search.html = function ( data ) {
|
||||
_div.innerHTML = data;
|
||||
|
||||
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
|
||||
* 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
|
||||
* @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 = [];
|
||||
$( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
|
||||
aData.push( this.checked==true ? "1" : "0" );
|
||||
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
|
||||
return $('input', td).prop('checked') ? '1' : '0';
|
||||
} );
|
||||
return aData;
|
||||
};
|
||||
|
@ -1,15 +1,16 @@
|
||||
/**
|
||||
* Read information from a column of select (drop down) menus and return an
|
||||
* 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
|
||||
* @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 = [];
|
||||
$( 'td:eq('+iColumn+') select', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
|
||||
aData.push( $(this).val() );
|
||||
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
|
||||
return $('select', td).val();
|
||||
} );
|
||||
return aData;
|
||||
};
|
||||
|
@ -1,15 +1,16 @@
|
||||
/**
|
||||
* Read information from a column of input (type text) elements and return an
|
||||
* 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
|
||||
* @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 = [];
|
||||
$( 'td:eq('+iColumn+') input', oSettings.oApi._fnGetTrNodes(oSettings) ).each( function () {
|
||||
aData.push( this.value );
|
||||
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
|
||||
return $('input', td).val();
|
||||
} );
|
||||
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
|
||||
* 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:
|
||||
* <ul>
|
||||
* <li>1/1/13 1:4 pm</li>
|
||||
* <li>01/01/2013 01:04 PM</li>
|
||||
* <li>1/1/2013 1:04 Pm</li>
|
||||
* </ul>
|
||||
* Adds a new sorting option to dataTables called `datetime-us`.
|
||||
*
|
||||
* Also included is a type detection plug-in. Matches and sorts date / time
|
||||
* strings in the format: `(m)m/(d)d/(yy)yy (h)h/m(m) (am|pm)`. For example:
|
||||
*
|
||||
* * 1/1/13 1:4 pm
|
||||
* * 01/01/2013 01:04 PM
|
||||
* * 1/1/2013 1:04 Pm
|
||||
*
|
||||
* @name Date / time - US
|
||||
* @anchor datetime_us
|
||||
* @author <a href="http://mrkmg.com/">Kevin Gravier</a>
|
||||
* @summary Sort date / time in the format `m/d/yy h:m am|pm`
|
||||
* @author [Kevin Gravier](http://mrkmg.com/)
|
||||
*
|
||||
* @example
|
||||
* $('#example').dataTable( {
|
||||
* columnDefs: [
|
||||
* { type: 'datetime-us', targets: 0 }
|
||||
* ]
|
||||
* } );
|
||||
*/
|
||||
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
|
||||
"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];
|
||||
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
|
||||
"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(ap == 'pm') hour = parseInt(hour, 10)+12;
|
||||
if (year.length == 2) {
|
||||
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){
|
||||
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;
|
||||
var tt = year + month + day + hour + min;
|
||||
return tt;
|
||||
}
|
||||
},
|
||||
|
||||
var tt = year+month+day+hour+min;
|
||||
return tt;
|
||||
},
|
||||
"datetime-us-asc": function ( a, b ) {
|
||||
return a - b;
|
||||
},
|
||||
"datetime-us-asc": function (a, b) {
|
||||
return a - b;
|
||||
},
|
||||
|
||||
"datetime-us-desc": function ( a, b ) {
|
||||
return b - a;
|
||||
}
|
||||
"datetime-us-desc": function (a, b) {
|
||||
return b - a;
|
||||
}
|
||||
});
|
||||
|
||||
jQuery.fn.dataTableExt.aTypes.unshift(
|
||||
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)/))
|
||||
{
|
||||
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)/)) {
|
||||
|
||||
return 'datetime-us';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return 'datetime-us';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in new issue