Merge branch 'master' of github.com:DataTables/Plugins

pull/518/head
Allan Jardine 4 years ago
commit c98b4c451e

@ -0,0 +1,79 @@
/**
* This renderer doesn't format the output itself, but rather allows multiple
* renderers to be easily called, which will render the content in sequence.
*
* Pass the renderers you wish to chain together as elements in an array to
* this function. Important - you should pass the renderer as if you were
* going to give it to the `render` property directly (i.e. if it is just a
* simple function, don't execute it).
*
* @name multi
* @summary Use multiple renderers
* @author [Allan Jardine](http://datatables.net)
* @requires DataTables 1.10+
*
* @example
* // Convert dates using moment renderer and ensure they are HTML safe
* $('#example').DataTable( {
* columnDefs: [ {
* targets: 1,
* render: $.fn.dataTable.render.multi( [
* $.fn.dataTable.render.moment( 'Do MMM YYYY' ),
* $.fn.dataTable.render.text(),
* ] )
* } ]
* } );
*/
// UMD
(function( factory ) {
"use strict";
if ( typeof define === 'function' && define.amd ) {
// AMD
define( ['jquery'], function ( $ ) {
return factory( $, window, document );
} );
}
else if ( typeof exports === 'object' ) {
// CommonJS
module.exports = function (root, $) {
if ( ! root ) {
root = window;
}
if ( ! $ ) {
$ = typeof window !== 'undefined' ?
require('jquery') :
require('jquery')( root );
}
return factory( $, root, root.document );
};
}
else {
// Browser
factory( jQuery, window, document );
}
}
(function( $, window, document ) {
$.fn.dataTable.render.multi = function (renderArray) {
return function (d, type, row, meta) {
for (var r = 0; r < renderArray.length; r++) {
if (typeof renderArray[r] === "function") {
d = renderArray[r](d, type, row, meta);
} else if (typeof renderArray[r][type] === "function") {
d = renderArray[r][type](d, type, row, meta);
} else if (typeof renderArray[r]._ === "function") {
d = renderArray[r]._(d, type, row, meta);
}
}
return d;
};
};
}));

@ -10,7 +10,6 @@ div.alphabet span {
color: #3174c7;
cursor: pointer;
text-align: center;
width: 3.5%
}
div.alphabet span:hover {

@ -11,7 +11,7 @@
* @author SpryMedia Ltd (www.sprymedia.co.uk)
* @contact www.sprymedia.co.uk/contact
* @copyright Copyright 2014 SpryMedia Ltd.
*
*
* License MIT - http://datatables.net/license/mit
*
* For more detailed information please see:
@ -49,8 +49,22 @@ $.fn.dataTable.ext.search.push( function ( context, searchData ) {
return true;
}
if ( searchData[0].charAt(0) === context.alphabetSearch ) {
return true;
if (context.oInit.alphabet !== undefined) {
var columnId = (context.oInit.alphabet.column !== undefined) ? context.oInit.alphabet.column : 0
var caseSensitive = (context.oInit.alphabet.caseSensitive !== undefined) ? context.oInit.alphabet.caseSensitive : false
} else {
var columnId = 0
var caseSensitive = false
}
if (caseSensitive) {
if ( searchData[columnId].charAt(0) === context.alphabetSearch ) {
return true;
}
} else {
if ( searchData[columnId].charAt(0).toUpperCase() === context.alphabetSearch ) {
return true;
}
}
return false;
@ -58,15 +72,21 @@ $.fn.dataTable.ext.search.push( function ( context, searchData ) {
// Private support methods
function bin ( data ) {
function bin ( data, options ) {
var letter, bins = {};
for ( var i=0, ien=data.length ; i<ien ; i++ ) {
letter = data[i]
.toString()
.replace(/<.*?>/g, '')
.charAt(0).toUpperCase();
if (options.caseSensitive) {
letter = data[i]
.toString()
.replace(/<.*?>/g, '')
.charAt(0);
} else {
letter = data[i]
.toString()
.replace(/<.*?>/g, '')
.charAt(0).toUpperCase();
}
if ( bins[letter] ) {
bins[letter]++;
}
@ -78,13 +98,13 @@ function bin ( data ) {
return bins;
}
function draw ( table, alphabet )
function draw ( table, alphabet, options )
{
alphabet.empty();
alphabet.append( 'Search: ' );
var columnData = table.column(0).data();
var bins = bin( columnData );
var columnData = table.column(options.column).data();
var bins = bin( columnData, options );
$('<span class="clear active"/>')
.data( 'letter', '' )
@ -92,6 +112,18 @@ function draw ( table, alphabet )
.html( 'None' )
.appendTo( alphabet );
if (options.numbers) {
for (var i = 0; i < 10; i++) {
var letter = String.fromCharCode(48 + i);
$('<span/>')
.data('letter', letter)
.data('match-count', bins[letter] || 0)
.addClass(!bins[letter] ? 'empty' : '')
.html(letter)
.appendTo(alphabet);
}
}
for ( var i=0 ; i<26 ; i++ ) {
var letter = String.fromCharCode( 65 + i );
@ -102,6 +134,18 @@ function draw ( table, alphabet )
.html( letter )
.appendTo( alphabet );
}
if (options.caseSensitive) {
for (var i = 0; i < 26; i++) {
var letter = String.fromCharCode(97 + i);
$('<span/>')
.data('letter', letter)
.data('match-count', bins[letter] || 0)
.addClass(!bins[letter] ? 'empty' : '')
.html(letter)
.appendTo(alphabet);
}
}
$('<div class="alphabetInfo"></div>')
.appendTo( alphabet );
@ -111,8 +155,13 @@ function draw ( table, alphabet )
$.fn.dataTable.AlphabetSearch = function ( context ) {
var table = new $.fn.dataTable.Api( context );
var alphabet = $('<div class="alphabet"/>');
var options = $.extend({
column: 0,
caseSensitive: false,
numbers: false
}, table.init().alphabet);
draw( table, alphabet );
draw( table, alphabet, options );
// Trigger a search
alphabet.on( 'click', 'span', function () {
@ -150,7 +199,6 @@ $.fn.dataTable.AlphabetSearch = function ( context ) {
$.fn.DataTable.AlphabetSearch = $.fn.dataTable.AlphabetSearch;
// Register a search plug-in
$.fn.dataTable.ext.feature.push( {
fnInit: function ( settings ) {

Loading…
Cancel
Save