33 (
function(window, document, undefined) {
36 var factory =
function( $, DataTable ) {
45 var ZeroClipboard_TableTools = {
47 version:
"1.0.4-TableTools2",
54 if (typeof(thingy) ==
'string') {
55 thingy = document.getElementById(thingy);
57 if (!thingy.addClass) {
59 thingy.hide =
function() { this.style.display =
'none'; };
60 thingy.show =
function() { this.style.display =
''; };
61 thingy.addClass =
function(name) { this.removeClass(name); this.className +=
' ' + name; };
62 thingy.removeClass =
function(name) {
63 this.className = this.className.replace(
new RegExp(
"\\s*" + name +
"\\s*"),
" ").replace(/^\s+/,
'').replace(/\s+$/,
'');
65 thingy.hasClass =
function(name) {
66 return !!this.className.match(
new RegExp(
"\\s*" + name +
"\\s*") );
72 setMoviePath:
function(path) {
74 this.moviePath = path;
77 dispatch:
function(id, eventName, args) {
79 var client = this.clients[id];
81 client.receiveEvent(eventName, args);
85 register:
function(id, client) {
87 this.clients[id] = client;
90 getDOMObjectPosition:
function(obj) {
95 width: obj.width ? obj.width : obj.offsetWidth,
96 height: obj.height ? obj.height : obj.offsetHeight
99 if ( obj.style.width !==
"" ) {
100 info.width = obj.style.width.replace(
"px",
"");
103 if ( obj.style.height !==
"" ) {
104 info.height = obj.style.height.replace(
"px",
"");
108 info.left += obj.offsetLeft;
109 info.top += obj.offsetTop;
110 obj = obj.offsetParent;
116 Client:
function(elem) {
121 this.
id = ZeroClipboard_TableTools.nextId++;
122 this.movieId =
'ZeroClipboard_TableToolsMovie_' + this.id;
125 ZeroClipboard_TableTools.register(this.
id,
this);
134 ZeroClipboard_TableTools.Client.prototype = {
142 handCursorEnabled:
true,
147 glue:
function(elem, title) {
150 this.domElement = ZeroClipboard_TableTools.$(elem);
154 if (this.domElement.style.zIndex) {
155 zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
159 var box = ZeroClipboard_TableTools.getDOMObjectPosition(this.domElement);
162 this.div = document.createElement(
'div');
163 var style = this.div.style;
164 style.position =
'absolute';
167 style.width = (box.width) +
'px';
168 style.height = box.height +
'px';
169 style.zIndex = zIndex;
171 if ( typeof title !=
"undefined" && title !==
"" ) {
172 this.div.title = title;
174 if ( box.width !== 0 && box.height !== 0 ) {
179 if ( this.domElement ) {
180 this.domElement.appendChild(this.div);
181 this.div.innerHTML = this.getHTML( box.width, box.height ).replace(/&/g,
'&');
185 positionElement:
function() {
186 var box = ZeroClipboard_TableTools.getDOMObjectPosition(this.domElement);
187 var style = this.div.style;
189 style.position =
'absolute';
192 style.width = box.width +
'px';
193 style.height = box.height +
'px';
195 if ( box.width !== 0 && box.height !== 0 ) {
201 var flash = this.div.childNodes[0];
202 flash.width = box.width;
203 flash.height = box.height;
206 getHTML:
function(width, height) {
209 var flashvars =
'id=' + this.
id +
213 if (navigator.userAgent.match(/MSIE/)) {
215 var protocol = location.href.match(/^https/i) ?
'https://' :
'http://';
216 html +=
'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="'+protocol+
'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="'+width+
'" height="'+height+
'" id="'+this.movieId+
'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard_TableTools.moviePath+
'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+
'"/><param name="wmode" value="transparent"/></object>';
220 html +=
'<embed id="'+this.movieId+
'" src="'+ZeroClipboard_TableTools.moviePath+
'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+
'" height="'+height+
'" name="'+this.movieId+
'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+
'" wmode="transparent" />';
228 this.div.style.left =
'-2000px';
237 destroy:
function() {
239 if (this.domElement && this.div) {
241 this.div.innerHTML =
'';
243 var body = document.getElementsByTagName(
'body')[0];
244 try { body.removeChild( this.div ); }
catch(e) {}
246 this.domElement = null;
251 reposition:
function(elem) {
255 this.domElement = ZeroClipboard_TableTools.$(elem);
256 if (!this.domElement) {
261 if (this.domElement && this.div) {
262 var box = ZeroClipboard_TableTools.getDOMObjectPosition(this.domElement);
263 var style = this.div.style;
264 style.left =
'' + box.left +
'px';
265 style.top =
'' + box.top +
'px';
269 clearText:
function() {
273 this.movie.clearText();
277 appendText:
function(newText) {
279 this.clipText += newText;
280 if (this.ready) { this.movie.appendText(newText) ;}
283 setText:
function(newText) {
285 this.clipText = newText;
286 if (this.ready) { this.movie.setText(newText) ;}
289 setCharSet:
function(charSet) {
291 this.charSet = charSet;
292 if (this.ready) { this.movie.setCharSet(charSet) ;}
295 setBomInc:
function(bomInc) {
297 this.incBom = bomInc;
298 if (this.ready) { this.movie.setBomInc(bomInc) ;}
301 setFileName:
function(newText) {
303 this.fileName = newText;
305 this.movie.setFileName(newText);
309 setAction:
function(newText) {
311 this.action = newText;
313 this.movie.setAction(newText);
317 addEventListener:
function(eventName, func) {
320 eventName = eventName.toString().toLowerCase().replace(/^on/,
'');
321 if (!this.handlers[eventName]) {
322 this.handlers[eventName] = [];
324 this.handlers[eventName].push(func);
327 setHandCursor:
function(enabled) {
329 this.handCursorEnabled = enabled;
331 this.movie.setHandCursor(enabled);
335 setCSSEffects:
function(enabled) {
337 this.cssEffects = !!enabled;
340 receiveEvent:
function(eventName, args) {
344 eventName = eventName.toString().toLowerCase().replace(/^on/,
'');
351 this.movie = document.getElementById(this.movieId);
354 setTimeout(
function() {
self.receiveEvent(
'load', null); }, 1 );
359 if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
361 setTimeout(
function() {
self.receiveEvent(
'load', null); }, 100 );
367 this.movie.clearText();
368 this.movie.appendText( this.clipText );
369 this.movie.setFileName( this.fileName );
370 this.movie.setAction( this.action );
371 this.movie.setCharSet( this.charSet );
372 this.movie.setBomInc( this.incBom );
373 this.movie.setHandCursor( this.handCursorEnabled );
377 if (this.domElement && this.cssEffects) {
379 if (this.recoverActive) {
380 this.domElement.addClass(
'active');
386 if (this.domElement && this.cssEffects) {
387 this.recoverActive =
false;
388 if (this.domElement.hasClass(
'active')) {
389 this.domElement.removeClass(
'active');
390 this.recoverActive =
true;
397 if (this.domElement && this.cssEffects) {
398 this.domElement.addClass(
'active');
403 if (this.domElement && this.cssEffects) {
404 this.domElement.removeClass(
'active');
405 this.recoverActive =
false;
410 if (this.handlers[eventName]) {
411 for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
412 var func = this.handlers[eventName][idx];
414 if (typeof(func) ==
'function') {
418 else if ((typeof(func) ==
'object') && (func.length == 2)) {
420 func[0][ func[1] ](
this, args);
422 else if (typeof(func) ==
'string') {
424 window[func](
this, args);
434 window.ZeroClipboard_TableTools = ZeroClipboard_TableTools;
443 (
function($, window, document) {
460 TableTools =
function( oDT, oOpts )
463 if ( !
this instanceof TableTools )
465 alert(
"Warning: TableTools must be initialised with the keyword 'new'" );
470 var dtSettings = $.fn.dataTable.Api ?
471 new $.fn.dataTable.Api( oDT ).settings()[0] :
533 "funcEnd":
function () {}
571 "preRowSelect": null,
579 "postSelected": null,
587 "postDeselected": null,
714 this.classes = $.extend(
true, {}, TableTools.classes );
715 if ( this.s.dt.bJUI )
717 $.extend(
true, this.classes, TableTools.classes_themeroller );
730 this.fnSettings =
function () {
736 if ( typeof oOpts ==
'undefined' )
742 TableTools._aInstances.push(
this );
743 this._fnConstruct( oOpts );
750 TableTools.prototype = {
763 "fnGetSelected":
function ( filtered )
767 data = this.s.dt.aoData,
768 displayed = this.s.dt.aiDisplay,
774 for ( i=0, iLen=displayed.length ; i<iLen ; i++ )
776 if ( data[ displayed[i] ]._DTTT_selected )
778 out.push( data[ displayed[i] ].nTr );
785 for ( i=0, iLen=data.length ; i<iLen ; i++ )
787 if ( data[i]._DTTT_selected )
789 out.push( data[i].nTr );
803 "fnGetSelectedData":
function ()
806 var data=this.s.dt.aoData;
809 for ( i=0, iLen=data.length ; i<iLen ; i++ )
811 if ( data[i]._DTTT_selected )
813 out.push( this.s.dt.oInstance.fnGetData(i) );
829 "fnGetSelectedIndexes":
function ( filtered )
833 data = this.s.dt.aoData,
834 displayed = this.s.dt.aiDisplay,
840 for ( i=0, iLen=displayed.length ; i<iLen ; i++ )
842 if ( data[ displayed[i] ]._DTTT_selected )
844 out.push( displayed[i] );
851 for ( i=0, iLen=data.length ; i<iLen ; i++ )
853 if ( data[i]._DTTT_selected )
869 "fnIsSelected":
function ( n )
871 var pos = this.s.dt.oInstance.fnGetPosition( n );
872 return (this.s.dt.aoData[pos]._DTTT_selected===
true) ?
true :
false;
882 "fnSelectAll":
function ( filtered )
884 this._fnRowSelect( filtered ?
885 this.s.dt.aiDisplay :
897 "fnSelectNone":
function ( filtered )
899 this._fnRowDeselect( this.fnGetSelectedIndexes(filtered) );
908 "fnSelect":
function ( n )
910 if ( this.s.select.type ==
"single" )
913 this._fnRowSelect( n );
917 this._fnRowSelect( n );
927 "fnDeselect":
function ( n )
929 this._fnRowDeselect( n );
939 "fnGetTitle":
function( oConfig )
942 if ( typeof oConfig.sTitle !=
'undefined' && oConfig.sTitle !==
"" ) {
943 sTitle = oConfig.sTitle;
945 var anTitle = document.getElementsByTagName(
'title');
946 if ( anTitle.length > 0 )
948 sTitle = anTitle[0].innerHTML;
955 if (
"\u00A1".toString().length < 4 ) {
956 return sTitle.replace(/[^a-zA-Z0-9_\u00A1-\uFFFF\.,\-_ !\(\)]/g,
"");
958 return sTitle.replace(/[^a-zA-Z0-9_\.,\-_ !\(\)]/g,
"");
970 "fnCalcColRatios":
function ( oConfig )
973 aoCols = this.s.dt.aoColumns,
974 aColumnsInc = this._fnColumnTargets( oConfig.mColumns ),
976 iWidth = 0, iTotal = 0, i, iLen;
978 for ( i=0, iLen=aColumnsInc.length ; i<iLen ; i++ )
980 if ( aColumnsInc[i] )
982 iWidth = aoCols[i].nTh.offsetWidth;
984 aColWidths.push( iWidth );
989 for ( i=0, iLen=aColWidths.length ; i<iLen ; i++ )
991 aColWidths[i] = aColWidths[i] / iTotal;
994 return aColWidths.join(
'\t');
1003 "fnGetTableData":
function ( oConfig )
1008 return this._fnGetDataTablesData( oConfig );
1018 "fnSetText":
function ( clip, text )
1020 this._fnFlashSetText( clip, text );
1029 "fnResizeButtons":
function ()
1031 for ( var cli in ZeroClipboard_TableTools.clients )
1035 var client = ZeroClipboard_TableTools.clients[cli];
1036 if ( typeof client.domElement !=
'undefined' &&
1037 client.domElement.parentNode )
1039 client.positionElement();
1049 "fnResizeRequired":
function ()
1051 for ( var cli in ZeroClipboard_TableTools.clients )
1055 var client = ZeroClipboard_TableTools.clients[cli];
1056 if ( typeof client.domElement !=
'undefined' &&
1057 client.domElement.parentNode ==
this.dom.container &&
1058 client.sized ===
false )
1079 "fnPrint":
function ( bView, oConfig )
1081 if ( oConfig === undefined )
1086 if ( bView === undefined || bView )
1088 this._fnPrintStart( oConfig );
1102 "fnInfo":
function ( message, time ) {
1103 var info = $(
'<div/>')
1104 .addClass( this.classes.print.info )
1106 .appendTo(
'body' );
1108 setTimeout(
function() {
1109 info.fadeOut(
"normal",
function() {
1121 "fnContainer":
function () {
1122 return this.dom.container;
1138 "_fnConstruct":
function ( oOpts )
1142 this._fnCustomiseSettings( oOpts );
1145 this.dom.container = document.createElement( this.s.tags.container );
1146 this.dom.container.className = this.classes.container;
1149 if ( this.s.select.type !=
'none' )
1151 this._fnRowSelectConfig();
1155 this._fnButtonDefinations( this.s.buttonSet,
this.dom.container );
1158 this.s.dt.aoDestroyCallback.push( {
1159 "sName":
"TableTools",
1162 .off(
'click.DTTT_Select', that.s.custom.sRowSelector )
1163 .off(
'mousedown.DTTT_Select',
'tr' )
1164 .off(
'mouseup.DTTT_Select',
'tr' );
1166 $.each( ZeroClipboard_TableTools.clients, function (
id, client ) {
1167 if ( client.domElement !== undefined &&
1168 $(client.domElement).parents( that.dom.container ).length )
1170 console.log(
'delete',
id );
1171 delete ZeroClipboard_TableTools.clients[ id ];
1175 $(that.dom.container).empty();
1178 var idx = $.inArray( that, TableTools._aInstances );
1180 TableTools._aInstances.splice( idx, 1 );
1194 "_fnCustomiseSettings":
function ( oOpts )
1197 if ( typeof this.s.dt._TableToolsInit ==
'undefined' )
1199 this.s.master =
true;
1200 this.s.dt._TableToolsInit =
true;
1204 this.dom.table = this.s.dt.nTable;
1207 this.s.custom = $.extend( {}, TableTools.DEFAULTS, oOpts );
1210 this.s.swfPath = this.s.custom.sSwfPath;
1211 if ( typeof ZeroClipboard_TableTools !=
'undefined' )
1213 ZeroClipboard_TableTools.moviePath = this.s.swfPath;
1217 this.s.select.type = this.s.custom.sRowSelect;
1218 this.s.select.preRowSelect = this.s.custom.fnPreRowSelect;
1219 this.s.select.postSelected = this.s.custom.fnRowSelected;
1220 this.s.select.postDeselected = this.s.custom.fnRowDeselected;
1223 if ( this.s.custom.sSelectedClass )
1225 this.classes.select.row = this.s.custom.sSelectedClass;
1228 this.s.tags = this.s.custom.oTags;
1231 this.s.buttonSet = this.s.custom.aButtons;
1244 "_fnButtonDefinations":
function ( buttonSet, wrapper )
1248 for ( var i=0, iLen=buttonSet.length ; i<iLen ; i++ )
1250 if ( typeof buttonSet[i] ==
"string" )
1252 if ( typeof TableTools.BUTTONS[ buttonSet[i] ] ==
'undefined' )
1254 alert(
"TableTools: Warning - unknown button type: "+buttonSet[i] );
1257 buttonDef = $.extend( {}, TableTools.BUTTONS[ buttonSet[i] ], true );
1261 if ( typeof TableTools.BUTTONS[ buttonSet[i].sExtends ] ==
'undefined' )
1263 alert(
"TableTools: Warning - unknown button type: "+buttonSet[i].sExtends );
1266 var o = $.extend( {}, TableTools.BUTTONS[ buttonSet[i].sExtends ], true );
1267 buttonDef = $.extend( o, buttonSet[i],
true );
1270 var button = this._fnCreateButton(
1272 $(wrapper).hasClass(this.classes.collection.container)
1276 wrapper.appendChild( button );
1289 "_fnCreateButton":
function ( oConfig, bCollectionButton )
1291 var nButton = this._fnButtonBase( oConfig, bCollectionButton );
1293 if ( oConfig.sAction.match(/flash/) )
1295 if ( ! this._fnHasFlash() ) {
1299 this._fnFlashConfig( nButton, oConfig );
1301 else if ( oConfig.sAction ==
"text" )
1303 this._fnTextConfig( nButton, oConfig );
1305 else if ( oConfig.sAction ==
"div" )
1307 this._fnTextConfig( nButton, oConfig );
1309 else if ( oConfig.sAction ==
"collection" )
1311 this._fnTextConfig( nButton, oConfig );
1312 this._fnCollectionConfig( nButton, oConfig );
1315 if ( this.s.dt.iTabIndex !== -1 ) {
1317 .attr(
'tabindex', this.s.dt.iTabIndex )
1318 .attr(
'aria-controls', this.s.dt.sTableId )
1319 .on(
'keyup.DTTT',
function (e) {
1323 if ( e.keyCode === 13 ) {
1324 e.stopPropagation();
1326 $(
this).trigger(
'click' );
1329 .on(
'mousedown.DTTT',
function (e) {
1336 if ( ! oConfig.sAction.match(/flash/) ) {
1353 "_fnButtonBase":
function ( o, bCollectionButton )
1355 var sTag, sLiner, sClass;
1357 if ( bCollectionButton )
1359 sTag = o.sTag && o.sTag !==
"default" ? o.sTag : this.s.tags.collection.button;
1360 sLiner = o.sLinerTag && o.sLinerTag !==
"default" ? o.sLiner : this.s.tags.collection.liner;
1361 sClass = this.classes.collection.buttons.normal;
1365 sTag = o.sTag && o.sTag !==
"default" ? o.sTag : this.s.tags.button;
1366 sLiner = o.sLinerTag && o.sLinerTag !==
"default" ? o.sLiner : this.s.tags.liner;
1367 sClass = this.classes.buttons.normal;
1371 nButton = document.createElement( sTag ),
1372 nSpan = document.createElement( sLiner ),
1373 masterS = this._fnGetMasterSettings();
1375 nButton.className = sClass+
" "+o.sButtonClass;
1376 nButton.setAttribute(
'id',
"ToolTables_"+this.s.dt.sInstance+
"_"+masterS.buttonCounter );
1377 nButton.appendChild( nSpan );
1378 nSpan.innerHTML = o.sButtonText;
1380 masterS.buttonCounter++;
1394 "_fnGetMasterSettings":
function ()
1396 if ( this.s.master )
1403 var instances = TableTools._aInstances;
1404 for ( var i=0, iLen=instances.length ; i<iLen ; i++ )
1406 if ( this.dom.table == instances[i].s.dt.nTable )
1408 return instances[i].s;
1427 "_fnCollectionConfig":
function ( nButton, oConfig )
1429 var nHidden = document.createElement( this.s.tags.collection.container );
1430 nHidden.style.display =
"none";
1431 nHidden.className = this.classes.collection.container;
1432 oConfig._collection = nHidden;
1433 document.body.appendChild( nHidden );
1435 this._fnButtonDefinations( oConfig.aButtons, nHidden );
1446 "_fnCollectionShow":
function ( nButton, oConfig )
1450 oPos = $(nButton).offset(),
1451 nHidden = oConfig._collection,
1453 iDivY = oPos.top + $(nButton).outerHeight(),
1454 iWinHeight = $(window).height(), iDocHeight = $(document).height(),
1455 iWinWidth = $(window).width(), iDocWidth = $(document).width();
1457 nHidden.style.position =
"absolute";
1458 nHidden.style.left = iDivX+
"px";
1459 nHidden.style.top = iDivY+
"px";
1460 nHidden.style.display =
"block";
1461 $(nHidden).
css(
'opacity',0);
1463 var nBackground = document.createElement(
'div');
1464 nBackground.style.position =
"absolute";
1465 nBackground.style.left =
"0px";
1466 nBackground.style.top =
"0px";
1467 nBackground.style.height = ((iWinHeight>iDocHeight)? iWinHeight : iDocHeight) +
"px";
1468 nBackground.style.width = ((iWinWidth>iDocWidth)? iWinWidth : iDocWidth) +
"px";
1469 nBackground.className = this.classes.collection.background;
1470 $(nBackground).
css(
'opacity',0);
1472 document.body.appendChild( nBackground );
1473 document.body.appendChild( nHidden );
1476 var iDivWidth = $(nHidden).outerWidth();
1477 var iDivHeight = $(nHidden).outerHeight();
1479 if ( iDivX + iDivWidth > iDocWidth )
1481 nHidden.style.left = (iDocWidth-iDivWidth)+
"px";
1484 if ( iDivY + iDivHeight > iDocHeight )
1486 nHidden.style.top = (iDivY-iDivHeight-$(nButton).outerHeight())+
"px";
1489 this.dom.collection.collection = nHidden;
1490 this.dom.collection.background = nBackground;
1495 setTimeout(
function () {
1496 $(nHidden).animate({
"opacity": 1}, 500);
1497 $(nBackground).animate({
"opacity": 0.25}, 500);
1501 this.fnResizeButtons();
1504 $(nBackground).click(
function () {
1505 that._fnCollectionHide.call( that, null, null );
1517 "_fnCollectionHide":
function ( nButton, oConfig )
1519 if ( oConfig !== null && oConfig.sExtends ==
'collection' )
1524 if ( this.dom.collection.collection !== null )
1526 $(this.dom.collection.collection).animate({
"opacity": 0}, 500,
function (e) {
1527 this.style.display =
"none";
1530 $(this.dom.collection.background).animate({
"opacity": 0}, 500,
function (e) {
1531 this.parentNode.removeChild(
this );
1534 this.dom.collection.collection = null;
1535 this.dom.collection.background = null;
1551 "_fnRowSelectConfig":
function ()
1553 if ( this.s.master )
1559 aoOpenRows = this.s.dt.aoOpenRows;
1561 $(dt.nTable).addClass( this.classes.select.table );
1566 if ( this.s.select.type ===
'os' ) {
1567 $(dt.nTBody).on(
'mousedown.DTTT_Select',
'tr',
function(e) {
1571 .
css(
'-moz-user-select',
'none' )
1572 .one(
'selectstart.DTTT_Select',
'tr',
function () {
1578 $(dt.nTBody).on(
'mouseup.DTTT_Select',
'tr',
function(e) {
1579 $(dt.nTBody).
css(
'-moz-user-select',
'' );
1584 $(dt.nTBody).on(
'click.DTTT_Select', this.s.custom.sRowSelector,
function(e) {
1585 var row = this.nodeName.toLowerCase() ===
'tr' ?
1587 $(
this).parents(
'tr')[0];
1589 var select = that.s.select;
1590 var pos = that.s.dt.oInstance.fnGetPosition( row );
1593 if ( row.parentNode != dt.nTBody ) {
1598 if ( dt.oInstance.fnGetData(row) === null ) {
1604 if ( select.type ==
'os' ) {
1605 if ( e.ctrlKey || e.metaKey ) {
1607 if ( that.fnIsSelected( row ) ) {
1608 that._fnRowDeselect( row, e );
1611 that._fnRowSelect( row, e );
1614 else if ( e.shiftKey ) {
1617 var rowIdxs = that.s.dt.aiDisplay.slice();
1618 var idx1 = $.inArray( select.lastRow, rowIdxs );
1619 var idx2 = $.inArray( pos, rowIdxs );
1621 if ( that.fnGetSelected().length === 0 || idx1 === -1 ) {
1624 rowIdxs.splice( $.inArray( pos, rowIdxs )+1, rowIdxs.length );
1628 if ( idx1 > idx2 ) {
1634 rowIdxs.splice( idx2+1, rowIdxs.length );
1635 rowIdxs.splice( 0, idx1 );
1638 if ( ! that.fnIsSelected( row ) ) {
1640 that._fnRowSelect( rowIdxs, e );
1644 rowIdxs.splice( $.inArray( pos, rowIdxs ), 1 );
1645 that._fnRowDeselect( rowIdxs, e );
1651 if ( that.fnIsSelected( row ) && that.fnGetSelected().length === 1 ) {
1652 that._fnRowDeselect( row, e );
1655 that.fnSelectNone();
1656 that._fnRowSelect( row, e );
1660 else if ( that.fnIsSelected( row ) ) {
1661 that._fnRowDeselect( row, e );
1663 else if ( select.type ==
"single" ) {
1664 that.fnSelectNone();
1665 that._fnRowSelect( row, e );
1667 else if ( select.type ==
"multi" ) {
1668 that._fnRowSelect( row, e );
1671 select.lastRow = pos;
1677 dt.oApi._fnCallbackReg( dt,
'aoRowCreatedCallback',
function (tr, data, index) {
1678 if ( dt.aoData[index]._DTTT_selected ) {
1679 $(tr).addClass( that.classes.select.row );
1681 },
'TableTools-SelectAll' );
1690 "_fnRowSelect":
function ( src, e )
1694 data = this._fnSelectData( src ),
1695 firstTr = data.length===0 ? null : data[0].nTr,
1700 for ( i=0, len=data.length ; i<len ; i++ )
1704 anSelected.push( data[i].nTr );
1709 if ( this.s.select.preRowSelect !== null && !
this.s.select.preRowSelect.call(
this, e, anSelected,
true) )
1715 for ( i=0, len=data.length ; i<len ; i++ )
1717 data[i]._DTTT_selected =
true;
1721 $(data[i].nTr).addClass( that.classes.select.row );
1726 if ( this.s.select.postSelected !== null )
1728 this.s.select.postSelected.call(
this, anSelected );
1731 TableTools._fnEventDispatch(
this,
'select', anSelected,
true );
1739 "_fnRowDeselect":
function ( src, e )
1743 data = this._fnSelectData( src ),
1744 firstTr = data.length===0 ? null : data[0].nTr,
1745 anDeselectedTrs = [],
1749 for ( i=0, len=data.length ; i<len ; i++ )
1753 anDeselectedTrs.push( data[i].nTr );
1758 if ( this.s.select.preRowSelect !== null && !
this.s.select.preRowSelect.call(
this, e, anDeselectedTrs,
false) )
1764 for ( i=0, len=data.length ; i<len ; i++ )
1766 data[i]._DTTT_selected =
false;
1770 $(data[i].nTr).removeClass( that.classes.select.row );
1775 if ( this.s.select.postDeselected !== null )
1777 this.s.select.postDeselected.call(
this, anDeselectedTrs );
1780 TableTools._fnEventDispatch(
this,
'select', anDeselectedTrs,
false );
1790 "_fnSelectData":
function ( src )
1792 var out = [], pos, i, iLen;
1797 pos = this.s.dt.oInstance.fnGetPosition( src );
1798 out.push( this.s.dt.aoData[pos] );
1800 else if ( typeof src.length !==
'undefined' )
1803 for ( i=0, iLen=src.length ; i<iLen ; i++ )
1805 if ( src[i].nodeName )
1807 pos = this.s.dt.oInstance.fnGetPosition( src[i] );
1808 out.push( this.s.dt.aoData[pos] );
1810 else if ( typeof src[i] ===
'number' )
1812 out.push( this.s.dt.aoData[ src[i] ] );
1822 else if ( typeof src ===
'number' )
1824 out.push(this.s.dt.aoData[src]);
1848 "_fnTextConfig":
function ( nButton, oConfig )
1852 if ( oConfig.fnInit !== null )
1854 oConfig.fnInit.call(
this, nButton, oConfig );
1857 if ( oConfig.sToolTip !==
"" )
1859 nButton.title = oConfig.sToolTip;
1862 $(nButton).hover(
function () {
1863 if ( oConfig.fnMouseover !== null )
1865 oConfig.fnMouseover.call(
this, nButton, oConfig, null );
1868 if ( oConfig.fnMouseout !== null )
1870 oConfig.fnMouseout.call(
this, nButton, oConfig, null );
1874 if ( oConfig.fnSelect !== null )
1876 TableTools._fnEventListen(
this,
'select',
function (n) {
1877 oConfig.fnSelect.call( that, nButton, oConfig, n );
1881 $(nButton).click(
function (e) {
1884 if ( oConfig.fnClick !== null )
1886 oConfig.fnClick.call( that, nButton, oConfig, null, e );
1890 if ( oConfig.fnComplete !== null )
1892 oConfig.fnComplete.call( that, nButton, oConfig, null, null );
1895 that._fnCollectionHide( nButton, oConfig );
1911 "_fnHasFlash":
function ()
1914 var fo =
new ActiveXObject(
'ShockwaveFlash.ShockwaveFlash');
1921 navigator.mimeTypes &&
1922 navigator.mimeTypes[
'application/x-shockwave-flash'] !== undefined &&
1923 navigator.mimeTypes[
'application/x-shockwave-flash'].enabledPlugin
1941 "_fnFlashConfig":
function ( nButton, oConfig )
1944 var flash =
new ZeroClipboard_TableTools.Client();
1946 if ( oConfig.fnInit !== null )
1948 oConfig.fnInit.call(
this, nButton, oConfig );
1951 flash.setHandCursor(
true );
1953 if ( oConfig.sAction ==
"flash_save" )
1955 flash.setAction(
'save' );
1956 flash.setCharSet( (oConfig.sCharSet==
"utf16le") ?
'UTF16LE' :
'UTF8' );
1957 flash.setBomInc( oConfig.bBomInc );
1958 flash.setFileName( oConfig.sFileName.replace(
'*',
this.fnGetTitle(oConfig)) );
1960 else if ( oConfig.sAction ==
"flash_pdf" )
1962 flash.setAction(
'pdf' );
1963 flash.setFileName( oConfig.sFileName.replace(
'*',
this.fnGetTitle(oConfig)) );
1967 flash.setAction(
'copy' );
1970 flash.addEventListener(
'mouseOver',
function(client) {
1971 if ( oConfig.fnMouseover !== null )
1973 oConfig.fnMouseover.call( that, nButton, oConfig, flash );
1977 flash.addEventListener(
'mouseOut',
function(client) {
1978 if ( oConfig.fnMouseout !== null )
1980 oConfig.fnMouseout.call( that, nButton, oConfig, flash );
1984 flash.addEventListener(
'mouseDown',
function(client) {
1985 if ( oConfig.fnClick !== null )
1987 oConfig.fnClick.call( that, nButton, oConfig, flash );
1991 flash.addEventListener(
'complete',
function (client, text) {
1992 if ( oConfig.fnComplete !== null )
1994 oConfig.fnComplete.call( that, nButton, oConfig, flash, text );
1996 that._fnCollectionHide( nButton, oConfig );
1999 if ( oConfig.fnSelect !== null )
2001 TableTools._fnEventListen(
this,
'select',
function (n) {
2002 oConfig.fnSelect.call( that, nButton, oConfig, n );
2006 this._fnFlashGlue( flash, nButton, oConfig.sToolTip );
2020 "_fnFlashGlue":
function ( flash, node, text )
2023 var
id = node.getAttribute(
'id');
2025 if ( document.getElementById(
id) )
2027 flash.glue( node, text );
2031 setTimeout(
function () {
2032 that._fnFlashGlue( flash, node, text );
2052 "_fnFlashSetText":
function ( clip, sData )
2054 var asData = this._fnChunkData( sData, 8192 );
2057 for ( var i=0, iLen=asData.length ; i<iLen ; i++ )
2059 clip.appendText( asData[i] );
2080 "_fnColumnTargets":
function ( mColumns )
2085 var columns = dt.aoColumns;
2086 var columnCount = columns.length;
2088 if ( typeof mColumns ==
"function" )
2090 var a = mColumns.call(
this, dt );
2092 for ( i=0, iLen=columnCount ; i<iLen ; i++ )
2094 aColumns.push( $.inArray( i, a ) !== -1 ?
true :
false );
2097 else if ( typeof mColumns ==
"object" )
2099 for ( i=0, iLen=columnCount ; i<iLen ; i++ )
2101 aColumns.push(
false );
2104 for ( i=0, iLen=mColumns.length ; i<iLen ; i++ )
2106 aColumns[ mColumns[i] ] =
true;
2109 else if ( mColumns ==
"visible" )
2111 for ( i=0, iLen=columnCount ; i<iLen ; i++ )
2113 aColumns.push( columns[i].bVisible ?
true :
false );
2116 else if ( mColumns ==
"hidden" )
2118 for ( i=0, iLen=columnCount ; i<iLen ; i++ )
2120 aColumns.push( columns[i].bVisible ?
false :
true );
2123 else if ( mColumns ==
"sortable" )
2125 for ( i=0, iLen=columnCount ; i<iLen ; i++ )
2127 aColumns.push( columns[i].bSortable ?
true :
false );
2132 for ( i=0, iLen=columnCount ; i<iLen ; i++ )
2134 aColumns.push(
true );
2148 "_fnNewline":
function ( oConfig )
2150 if ( oConfig.sNewLine ==
"auto" )
2152 return navigator.userAgent.match(/Windows/) ?
"\r\n" :
"\n";
2156 return oConfig.sNewLine;
2175 "_fnGetDataTablesData":
function ( oConfig )
2177 var i, iLen, j, jLen;
2178 var aRow, aData=[], sLoopData=
'', arr;
2179 var dt = this.s.dt, tr, child;
2180 var regex =
new RegExp(oConfig.sFieldBoundary,
"g");
2181 var aColumnsInc = this._fnColumnTargets( oConfig.mColumns );
2182 var bSelectedOnly = (typeof oConfig.bSelectedOnly !=
'undefined') ? oConfig.bSelectedOnly :
false;
2187 if ( oConfig.bHeader )
2191 for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ )
2193 if ( aColumnsInc[i] )
2195 sLoopData = dt.aoColumns[i].sTitle.replace(/\n/g,
" ").replace( /<.*?>/g,
"" ).replace(/^\s+|\s+$/g,
"");
2196 sLoopData = this._fnHtmlDecode( sLoopData );
2198 aRow.push( this._fnBoundData( sLoopData, oConfig.sFieldBoundary, regex ) );
2202 aData.push( aRow.join(oConfig.sFieldSeperator) );
2205 bSelectedOnly =
true;
2211 var aSelected = this.fnGetSelectedIndexes();
2212 bSelectedOnly = this.s.select.type !==
"none" && bSelectedOnly && aSelected.length !== 0;
2214 if ( bSelectedOnly ) {
2216 aDataIndex = aSelected;
2218 else if ( DataTable.Api ) {
2220 aDataIndex =
new DataTable.Api( dt )
2221 .rows( oConfig.oSelectorOpts )
2228 aDataIndex = dt.oInstance
2229 .$(
'tr', oConfig.oSelectorOpts)
2230 .map(
function (
id, row) {
2231 return dt.oInstance.fnGetPosition( row );
2236 for ( j=0, jLen=aDataIndex.length ; j<jLen ; j++ )
2238 tr = dt.aoData[ aDataIndex[j] ].nTr;
2242 for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ )
2244 if ( aColumnsInc[i] )
2247 var mTypeData = dt.oApi._fnGetCellData( dt, aDataIndex[j], i,
'display' );
2248 if ( oConfig.fnCellRender )
2250 sLoopData = oConfig.fnCellRender( mTypeData, i, tr, aDataIndex[j] )+
"";
2252 else if ( typeof mTypeData ==
"string" )
2255 sLoopData = mTypeData.replace(/\n/g,
" ");
2257 sLoopData.replace(/<img.*?\s+alt\s*=\s*(?:
"([^"]+)
"|'([^']+)'|([^\s>]+)).*?>/gi,
2259 sLoopData = sLoopData.replace( /<.*?>/g, "" );
2263 sLoopData = mTypeData+"";
2266 /* Trim and clean the data */
2267 sLoopData = sLoopData.replace(/^\s+/, '').replace(/\s+$/, '');
2268 sLoopData = this._fnHtmlDecode( sLoopData );
2270 /* Bound it and add it to the total data */
2271 aRow.push( this._fnBoundData( sLoopData, oConfig.sFieldBoundary, regex ) );
2275 aData.push( aRow.join(oConfig.sFieldSeperator) );
2277 /* Details rows from fnOpen */
2278 if ( oConfig.bOpenRows )
2280 arr = $.grep(dt.aoOpenRows, function(o) { return o.nParent === tr; });
2282 if ( arr.length === 1 )
2284 sLoopData = this._fnBoundData( $('td', arr[0].nTr).html(), oConfig.sFieldBoundary, regex );
2285 aData.push( sLoopData );
2293 if ( oConfig.bFooter && dt.nTFoot !== null )
2297 for ( i=0, iLen=dt.aoColumns.length ; i<iLen ; i++ )
2299 if ( aColumnsInc[i] && dt.aoColumns[i].nTf !== null )
2301 sLoopData = dt.aoColumns[i].nTf.innerHTML.replace(/\n/g," ").replace( /<.*?>/g, "" );
2302 sLoopData = this._fnHtmlDecode( sLoopData );
2304 aRow.push( this._fnBoundData( sLoopData, oConfig.sFieldBoundary, regex ) );
2308 aData.push( aRow.join(oConfig.sFieldSeperator) );
2311 var _sLastData = aData.join( this._fnNewline(oConfig) );
2326 "_fnBoundData
": function ( sData, sBoundary, regex )
2328 if ( sBoundary === "" )
2334 return sBoundary + sData.replace(regex, sBoundary+sBoundary) + sBoundary;
2347 "_fnChunkData
": function ( sData, iSize )
2350 var iStrlen = sData.length;
2352 for ( var i=0 ; i<iStrlen ; i+=iSize )
2354 if ( i+iSize < iStrlen )
2356 asReturn.push( sData.substring( i, i+iSize ) );
2360 asReturn.push( sData.substring( i, iStrlen ) );
2375 "_fnHtmlDecode
": function ( sData )
2377 if ( sData.indexOf('&') === -1 )
2382 var n = document.createElement('div');
2384 return sData.replace( /&([^\s]*?);/g, function( match, match2 ) {
2385 if ( match.substr(1, 1) === '#' )
2387 return String.fromCharCode( Number(match2.substr(1)) );
2391 n.innerHTML = match;
2392 return n.childNodes[0].nodeValue;
2399 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2400 * Printing functions
2411 "_fnPrintStart
": function ( oConfig )
2414 var oSetDT = this.s.dt;
2416 /* Parse through the DOM hiding everything that isn't needed for the table */
2417 this._fnPrintHideNodes( oSetDT.nTable );
2419 /* Show the whole table */
2420 this.s.print.saveStart = oSetDT._iDisplayStart;
2421 this.s.print.saveLength = oSetDT._iDisplayLength;
2423 if ( oConfig.bShowAll )
2425 oSetDT._iDisplayStart = 0;
2426 oSetDT._iDisplayLength = -1;
2427 if ( oSetDT.oApi._fnCalculateEnd ) {
2428 oSetDT.oApi._fnCalculateEnd( oSetDT );
2430 oSetDT.oApi._fnDraw( oSetDT );
2433 /* Adjust the display for scrolling which might be done by DataTables */
2434 if ( oSetDT.oScroll.sX !== "" || oSetDT.oScroll.sY !== "" )
2436 this._fnPrintScrollStart( oSetDT );
2438 // If the table redraws while in print view, the DataTables scrolling
2439 // setup would hide the header, so we need to readd it on draw
2440 $(this.s.dt.nTable).bind('draw.DTTT_Print', function () {
2441 that._fnPrintScrollStart( oSetDT );
2445 /* Remove the other DataTables feature nodes - but leave the table! and info div */
2446 var anFeature = oSetDT.aanFeatures;
2447 for ( var cFeature in anFeature )
2449 if ( cFeature != 'i' && cFeature != 't' && cFeature.length == 1 )
2451 for ( var i=0, iLen=anFeature[cFeature].length ; i<iLen ; i++ )
2453 this.dom.print.hidden.push( {
2454 "node
": anFeature[cFeature][i],
2457 anFeature[cFeature][i].style.display = "none
";
2462 /* Print class can be used for styling */
2463 $(document.body).addClass( this.classes.print.body );
2465 /* Show information message to let the user know what is happening */
2466 if ( oConfig.sInfo !== "" )
2468 this.fnInfo( oConfig.sInfo, 3000 );
2471 /* Add a message at the top of the page */
2472 if ( oConfig.sMessage )
2475 .addClass( this.classes.print.message )
2476 .html( oConfig.sMessage )
2477 .prependTo( 'body' );
2480 /* Cache the scrolling and the jump to the top of the page */
2481 this.s.print.saveScroll = $(window).scrollTop();
2482 window.scrollTo( 0, 0 );
2484 /* Bind a key event listener to the document for the escape key -
2485 * it is removed in the callback
2487 $(document).bind( "keydown.DTTT
", function(e) {
2488 /* Only interested in the escape key */
2489 if ( e.keyCode == 27 )
2492 that._fnPrintEnd.call( that, e );
2505 "_fnPrintEnd
": function ( e )
2508 var oSetDT = this.s.dt;
2509 var oSetPrint = this.s.print;
2510 var oDomPrint = this.dom.print;
2512 /* Show all hidden nodes */
2513 this._fnPrintShowNodes();
2515 /* Restore DataTables' scrolling */
2516 if ( oSetDT.oScroll.sX !== "" || oSetDT.oScroll.sY !== "" )
2518 $(this.s.dt.nTable).unbind('draw.DTTT_Print');
2520 this._fnPrintScrollEnd();
2523 /* Restore the scroll */
2524 window.scrollTo( 0, oSetPrint.saveScroll );
2526 /* Drop the print message */
2527 $('div.'+this.classes.print.message).remove();
2530 $(document.body).removeClass( this.classes.print.body );
2532 /* Restore the table length */
2533 oSetDT._iDisplayStart = oSetPrint.saveStart;
2534 oSetDT._iDisplayLength = oSetPrint.saveLength;
2535 if ( oSetDT.oApi._fnCalculateEnd ) {
2536 oSetDT.oApi._fnCalculateEnd( oSetDT );
2538 oSetDT.oApi._fnDraw( oSetDT );
2540 $(document).unbind( "keydown.DTTT
" );
2549 "_fnPrintScrollStart
": function ()
2553 nScrollHeadInner = oSetDT.nScrollHead.getElementsByTagName('div')[0],
2554 nScrollHeadTable = nScrollHeadInner.getElementsByTagName('table')[0],
2555 nScrollBody = oSetDT.nTable.parentNode,
2556 nTheadSize, nTfootSize;
2558 /* Copy the header in the thead in the body table, this way we show one single table when
2559 * in print view. Note that this section of code is more or less verbatim from DT 1.7.0
2561 nTheadSize = oSetDT.nTable.getElementsByTagName('thead');
2562 if ( nTheadSize.length > 0 )
2564 oSetDT.nTable.removeChild( nTheadSize[0] );
2567 if ( oSetDT.nTFoot !== null )
2569 nTfootSize = oSetDT.nTable.getElementsByTagName('tfoot');
2570 if ( nTfootSize.length > 0 )
2572 oSetDT.nTable.removeChild( nTfootSize[0] );
2576 nTheadSize = oSetDT.nTHead.cloneNode(true);
2577 oSetDT.nTable.insertBefore( nTheadSize, oSetDT.nTable.childNodes[0] );
2579 if ( oSetDT.nTFoot !== null )
2581 nTfootSize = oSetDT.nTFoot.cloneNode(true);
2582 oSetDT.nTable.insertBefore( nTfootSize, oSetDT.nTable.childNodes[1] );
2585 /* Now adjust the table's viewport so we can actually see it */
2586 if ( oSetDT.oScroll.sX !== "" )
2588 oSetDT.nTable.style.width = $(oSetDT.nTable).outerWidth()+"px
";
2589 nScrollBody.style.width = $(oSetDT.nTable).outerWidth()+"px
";
2590 nScrollBody.style.overflow = "visible
";
2593 if ( oSetDT.oScroll.sY !== "" )
2595 nScrollBody.style.height = $(oSetDT.nTable).outerHeight()+"px
";
2596 nScrollBody.style.overflow = "visible
";
2607 "_fnPrintScrollEnd
": function ()
2611 nScrollBody = oSetDT.nTable.parentNode;
2613 if ( oSetDT.oScroll.sX !== "" )
2615 nScrollBody.style.width = oSetDT.oApi._fnStringToCss( oSetDT.oScroll.sX );
2616 nScrollBody.style.overflow = "auto";
2619 if ( oSetDT.oScroll.sY !== "" )
2621 nScrollBody.style.height = oSetDT.oApi._fnStringToCss( oSetDT.oScroll.sY );
2622 nScrollBody.style.overflow = "auto";
2633 "_fnPrintShowNodes
": function ( )
2635 var anHidden = this.dom.print.hidden;
2637 for ( var i=0, iLen=anHidden.length ; i<iLen ; i++ )
2639 anHidden[i].node.style.display = anHidden[i].display;
2641 anHidden.splice( 0, anHidden.length );
2653 "_fnPrintHideNodes
": function ( nNode )
2655 var anHidden = this.dom.print.hidden;
2657 var nParent = nNode.parentNode;
2658 var nChildren = nParent.childNodes;
2659 for ( var i=0, iLen=nChildren.length ; i<iLen ; i++ )
2661 if ( nChildren[i] != nNode && nChildren[i].nodeType == 1 )
2663 /* If our node is shown (don't want to show nodes which were previously hidden) */
2664 var sDisplay = $(nChildren[i]).css("display
");
2665 if ( sDisplay != "none
" )
2667 /* Cache the node and it's previous state so we can restore it */
2669 "node
": nChildren[i],
2672 nChildren[i].style.display = "none
";
2677 if ( nParent.nodeName.toUpperCase() != "BODY
" )
2679 this._fnPrintHideNodes( nParent );
2686 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2688 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2698 TableTools._aInstances = [];
2707 TableTools._aListeners = [];
2711 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2713 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2721 TableTools.fnGetMasters = function ()
2724 for ( var i=0, iLen=TableTools._aInstances.length ; i<iLen ; i++ )
2726 if ( TableTools._aInstances[i].s.master )
2728 a.push( TableTools._aInstances[i] );
2740 TableTools.fnGetInstance = function ( node )
2742 if ( typeof node != 'object' )
2744 node = document.getElementById(node);
2747 for ( var i=0, iLen=TableTools._aInstances.length ; i<iLen ; i++ )
2749 if ( TableTools._aInstances[i].s.master && TableTools._aInstances[i].dom.table == node )
2751 return TableTools._aInstances[i];
2768 TableTools._fnEventListen = function ( that, type, fn )
2770 TableTools._aListeners.push( {
2790 TableTools._fnEventDispatch = function ( that, type, node, selected )
2792 var listeners = TableTools._aListeners;
2793 for ( var i=0, iLen=listeners.length ; i<iLen ; i++ )
2795 if ( that.dom.table == listeners[i].that.dom.table && listeners[i].type == type )
2797 listeners[i].fn( node, selected );
2807 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2809 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2813 TableTools.buttonBase = {
2817 "sLinerTag
": "default",
2818 "sButtonClass
": "DTTT_button_text
",
2819 "sButtonText
": "Button text
",
2823 // Common button specific options
2826 "sFileName
": "*.csv
",
2827 "sFieldBoundary
": "",
2828 "sFieldSeperator
": "\t
",
2830 "mColumns
": "all
", /* "all
", "visible
", "hidden
" or array of column integers */
2834 "bSelectedOnly
": false,
2835 "oSelectorOpts
": undefined, // See http://datatables.net/docs/DataTables/1.9.4/#$ for full options
2838 "fnMouseover
": null,
2844 "fnCellRender
": null
2851 TableTools.BUTTONS = {
2852 "csv
": $.extend( {}, TableTools.buttonBase, {
2853 "sAction
": "flash_save
",
2854 "sButtonClass
": "DTTT_button_csv
",
2855 "sButtonText
": "CSV
",
2856 "sFieldBoundary
": '"',
2857 "sFieldSeperator": ",",
2858 "fnClick": function( nButton, oConfig, flash ) {
2859 this.fnSetText( flash, this.fnGetTableData(oConfig) );
2863 "xls": $.extend( {}, TableTools.buttonBase, {
2864 "sAction": "flash_save",
2865 "sCharSet": "utf16le",
2867 "sButtonClass": "DTTT_button_xls",
2868 "sButtonText": "Excel",
2869 "fnClick": function( nButton, oConfig, flash ) {
2870 this.fnSetText( flash, this.fnGetTableData(oConfig) );
2874 "copy": $.extend( {}, TableTools.buttonBase, {
2875 "sAction": "flash_copy",
2876 "sButtonClass": "DTTT_button_copy",
2877 "sButtonText": "Copy",
2878 "fnClick": function( nButton, oConfig, flash ) {
2879 this.fnSetText( flash, this.fnGetTableData(oConfig) );
2881 "fnComplete": function(nButton, oConfig, flash, text) {
2882 var lines = text.split('\n
').length;
2883 if (oConfig.bHeader) lines--;
2884 if (this.s.dt.nTFoot !== null && oConfig.bFooter) lines--;
2885 var plural = (lines==1) ? "" : "s";
2886 this.fnInfo( '<h6>Table copied</h6>
'+
2887 '<p>Copied
'+lines+' row
'+plural+' to the clipboard.</p>
',
2893 "pdf": $.extend( {}, TableTools.buttonBase, {
2894 "sAction": "flash_pdf",
2896 "sFileName": "*.pdf",
2897 "sButtonClass": "DTTT_button_pdf",
2898 "sButtonText": "PDF",
2899 "sPdfOrientation": "portrait",
2902 "fnClick": function( nButton, oConfig, flash ) {
2903 this.fnSetText( flash,
2904 "title:"+ this.fnGetTitle(oConfig) +"\n"+
2905 "message:"+ oConfig.sPdfMessage +"\n"+
2906 "colWidth:"+ this.fnCalcColRatios(oConfig) +"\n"+
2907 "orientation:"+ oConfig.sPdfOrientation +"\n"+
2908 "size:"+ oConfig.sPdfSize +"\n"+
2909 "--/TableToolsOpts--\n" +
2910 this.fnGetTableData(oConfig)
2915 "print": $.extend( {}, TableTools.buttonBase, {
2916 "sInfo": "<h6>Print view</h6><p>Please use your browser's print
function to
"+
2917 "print
this table. Press escape when finished.</p>
",
2920 "sToolTip
": "View print view
",
2921 "sButtonClass
": "DTTT_button_print
",
2922 "sButtonText
": "Print
",
2923 "fnClick
": function ( nButton, oConfig ) {
2924 this.fnPrint( true, oConfig );
2928 "text
": $.extend( {}, TableTools.buttonBase ),
2930 "select
": $.extend( {}, TableTools.buttonBase, {
2931 "sButtonText
": "Select button
",
2932 "fnSelect
": function( nButton, oConfig ) {
2933 if ( this.fnGetSelected().length !== 0 ) {
2934 $(nButton).removeClass( this.classes.buttons.disabled );
2936 $(nButton).addClass( this.classes.buttons.disabled );
2939 "fnInit
": function( nButton, oConfig ) {
2940 $(nButton).addClass( this.classes.buttons.disabled );
2944 "select_single
": $.extend( {}, TableTools.buttonBase, {
2945 "sButtonText
": "Select button
",
2946 "fnSelect
": function( nButton, oConfig ) {
2947 var iSelected = this.fnGetSelected().length;
2948 if ( iSelected == 1 ) {
2949 $(nButton).removeClass( this.classes.buttons.disabled );
2951 $(nButton).addClass( this.classes.buttons.disabled );
2954 "fnInit
": function( nButton, oConfig ) {
2955 $(nButton).addClass( this.classes.buttons.disabled );
2959 "select_all
": $.extend( {}, TableTools.buttonBase, {
2960 "sButtonText
": "Select all
",
2961 "fnClick
": function( nButton, oConfig ) {
2964 "fnSelect
": function( nButton, oConfig ) {
2965 if ( this.fnGetSelected().length == this.s.dt.fnRecordsDisplay() ) {
2966 $(nButton).addClass( this.classes.buttons.disabled );
2968 $(nButton).removeClass( this.classes.buttons.disabled );
2973 "select_none
": $.extend( {}, TableTools.buttonBase, {
2974 "sButtonText
": "Deselect all
",
2975 "fnClick
": function( nButton, oConfig ) {
2976 this.fnSelectNone();
2978 "fnSelect
": function( nButton, oConfig ) {
2979 if ( this.fnGetSelected().length !== 0 ) {
2980 $(nButton).removeClass( this.classes.buttons.disabled );
2982 $(nButton).addClass( this.classes.buttons.disabled );
2985 "fnInit
": function( nButton, oConfig ) {
2986 $(nButton).addClass( this.classes.buttons.disabled );
2990 "ajax
": $.extend( {}, TableTools.buttonBase, {
2991 "sAjaxUrl
": "/xhr.php
",
2992 "sButtonText
": "Ajax button
",
2993 "fnClick
": function( nButton, oConfig ) {
2994 var sData = this.fnGetTableData(oConfig);
2996 "url": oConfig.sAjaxUrl,
2998 { "name
": "tableData
", "value
": sData }
3000 "success
": oConfig.fnAjaxComplete,
3004 "error
": function () {
3005 alert( "Error detected when sending table data to server
" );
3009 "fnAjaxComplete
": function( json ) {
3010 alert( 'Ajax complete' );
3014 "div
": $.extend( {}, TableTools.buttonBase, {
3017 "sButtonClass
": "DTTT_nonbutton
",
3018 "sButtonText
": "Text button
"
3021 "collection
": $.extend( {}, TableTools.buttonBase, {
3022 "sAction
": "collection
",
3023 "sButtonClass
": "DTTT_button_collection
",
3024 "sButtonText
": "Collection
",
3025 "fnClick
": function( nButton, oConfig ) {
3026 this._fnCollectionShow(nButton, oConfig);
3031 * on* callback parameters:
3032 * 1. node - button element
3033 * 2. object - configuration object for this button
3034 * 3. object - ZeroClipboard reference (flash button only)
3035 * 4. string - Returned string from Flash (flash button only - and only on 'complete')
3038 // Alias to match the other plug-ins styling
3039 TableTools.buttons = TableTools.BUTTONS;
3047 TableTools.classes = {
3048 "container
": "DTTT_container
",
3050 "normal
": "DTTT_button
",
3051 "disabled
": "DTTT_disabled
"
3054 "container
": "DTTT_collection
",
3055 "background
": "DTTT_collection_background
",
3057 "normal
": "DTTT_button
",
3058 "disabled
": "DTTT_disabled
"
3062 "table
": "DTTT_selectable
",
3063 "row
": "DTTT_selected selected
"
3066 "body
": "DTTT_Print
",
3067 "info
": "DTTT_print_info
",
3068 "message
": "DTTT_PrintMessage
"
3077 TableTools.classes_themeroller = {
3078 "container
": "DTTT_container ui-buttonset ui-buttonset-multi
",
3080 "normal
": "DTTT_button ui-button ui-state-
default"
3083 "container
": "DTTT_collection ui-buttonset ui-buttonset-multi
"
3091 TableTools.DEFAULTS = {
3092 "sSwfPath
": "../swf/copy_csv_xls_pdf.swf
",
3093 "sRowSelect
": "none
",
3094 "sRowSelector
": "tr
",
3095 "sSelectedClass
": null,
3096 "fnPreRowSelect
": null,
3097 "fnRowSelected
": null,
3098 "fnRowDeselected
": null,
3099 "aButtons
": [ "copy
", "csv
", "xls
", "pdf
", "print
" ],
3102 "button
": "a
", // We really want to use buttons here, but Firefox and IE ignore the
3103 // click on the Flash element in the button (but not mouse[in|out]).
3113 // Alias to match the other plug-ins
3114 TableTools.defaults = TableTools.DEFAULTS;
3123 TableTools.prototype.CLASS = "TableTools
";
3132 TableTools.version = "2.2.4
";
3136 // DataTables 1.10 API
3138 // This will be extended in a big way in in TableTools 3 to provide API methods
3139 // such as rows().select() and rows.selected() etc, but for the moment the
3140 // tabletools() method simply returns the instance.
3142 if ( $.fn.dataTable.Api ) {
3143 $.fn.dataTable.Api.register( 'tabletools()', function () {
3146 if ( this.context.length > 0 ) {
3147 tt = TableTools.fnGetInstance( this.context[0].nTable );
3157 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3159 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
3162 * Register a new feature with DataTables
3164 if ( typeof $.fn.dataTable == "function" &&
3165 typeof $.fn.dataTableExt.fnVersionCheck == "function" &&
3166 $.fn.dataTableExt.fnVersionCheck('1.9.0') )
3168 $.fn.dataTableExt.aoFeatures.push( {
3169 "fnInit
": function( oDTSettings ) {
3170 var init = oDTSettings.oInit;
3172 init.tableTools || init.oTableTools || {} :
3175 return new TableTools( oDTSettings.oInstance, opts ).dom.container;
3178 "sFeature
": "TableTools
"
3183 alert( "Warning: TableTools requires DataTables 1.9.0 or newer - www.datatables.net/download
");
3186 $.fn.DataTable.TableTools = TableTools;
3188 })(jQuery, window, document);
3191 * Register a new feature with DataTables
3193 if ( typeof $.fn.dataTable == "function" &&
3194 typeof $.fn.dataTableExt.fnVersionCheck == "function" &&
3195 $.fn.dataTableExt.fnVersionCheck('1.9.0') )
3197 $.fn.dataTableExt.aoFeatures.push( {
3198 "fnInit
": function( oDTSettings ) {
3199 var oOpts = typeof oDTSettings.oInit.oTableTools != 'undefined' ?
3200 oDTSettings.oInit.oTableTools : {};
3202 var oTT = new TableTools( oDTSettings.oInstance, oOpts );
3203 TableTools._aInstances.push( oTT );
3205 return oTT.dom.container;
3208 "sFeature
": "TableTools
"
3213 alert( "Warning: TableTools 2 requires DataTables 1.9.0 or newer - www.datatables.net/download
");
3217 $.fn.dataTable.TableTools = TableTools;
3218 $.fn.DataTable.TableTools = TableTools;
3225 // Define as an AMD module if possible
3226 if ( typeof define === 'function' && define.amd ) {
3227 define( ['jquery', 'datatables'], factory );
3229 else if ( typeof exports === 'object' ) {
3231 factory( require('jquery'), require('datatables') );
3233 else if ( jQuery && !jQuery.fn.dataTable.TableTools ) {
3234 // Otherwise simply initialise as normal, stopping multiple evaluation
3235 factory( jQuery, jQuery.fn.dataTable );
3239 })(window, document);