diff --git a/api/processing().js b/api/processing().js index 4006fc6..84164aa 100644 --- a/api/processing().js +++ b/api/processing().js @@ -1,5 +1,8 @@ /** - * Externally trigger the display of DataTables' "processing" indicator. + * Externally trigger the display of DataTables' "processing" indicator. + * + * Please note that of DataTables 2.0.0 this functionality is now built into + * DataTables core and this plug-in is no longer required. * * @name processing() * @summary Show / hide the processing indicator via the API diff --git a/api/rows().generate().js b/api/rows().generate().js new file mode 100644 index 0000000..ba4475f --- /dev/null +++ b/api/rows().generate().js @@ -0,0 +1,22 @@ +/** + * When using `-init deferRender` you might find that under a specific set of circumstances you + * need the `-tag tr` element for a row which hasn't yet been drawn. This method can be used to + * create the nodes for the rows which haven't yet been drawn. + * + * @name rows().generate() + * @summary Create tr elements for rows which have not yet had their nodes created. + * @author [Allan Jardine](http://datatables.net) + * @requires DataTables 1.10+ + * + * @returns {DataTable.Api} DataTables API instance + * + * @example + * // Create nodes for all rows + * table.rows().generate(); + */ + + $.fn.dataTable.Api.register( 'rows().generate()', function () { + return this.iterator( 'row', function ( context, index ) { + context.oApi._fnCreateTr( context, index ); + } ); +} ); \ No newline at end of file diff --git a/buttons/button.download.js b/buttons/button.download.js new file mode 100644 index 0000000..36de995 --- /dev/null +++ b/buttons/button.download.js @@ -0,0 +1,113 @@ +/*! Download button for Buttons + * 2018 SpryMedia Ltd - MIT licensed - datatables.net/license + */ + +/** + * @summary Download Button + * @author SpryMedia Ltd (www.datatables.net) + * @copyright Copyright 2018 SpryMedia Ltd. + * + * License MIT - http://datatables.net/license/mit + * + * A button that can be used to trigger a server-side action, typically a + * download of a file generated by the server. If server-side processing + * is enabled in the host table it will automatically add the last parameters + * used for a table draw allowing the script to output a file with the same + * order / search applied as the main table. + * + * This is particularly useful when using server-side processing and wishing + * to allow user export of the data in a table. The default Buttons package + * will only export the data available on the client-side, while this button + * can be used to let the server generate the required file and then download + * it to the client-side. + * + * @example + * // Download button + * var table = $('#example').DataTable({ + * dom: 'Bfrtip', + * buttons: [ + * { + * extend: 'download', + * url: '/api/download' + * } + * ] + * }); + */ +(function(window, document, $, undefined) { + function flattenJson(data, name, flattened) { + if (!flattened) { + flattened = {}; + } + + if (!name) { + name = ''; + } + + if ($.isPlainObject(data) || $.isArray(data)) { + $.each(data, function(idx, val) { + if (name === '') { + flattenJson(val, idx, flattened); + } else { + flattenJson(val, name + '[' + idx + ']', flattened); + } + }); + } else { + flattened[name] = data; + } + + return flattened; + } + + $.fn.dataTable.ext.buttons.download = { + text: 'Download', + action: function(e, dt, node, config) { + // Gather information to be submitted + var data = {}; + + if (dt.page.info().serverSide) { + $.extend(data, dt.ajax.params()); + } + + if (typeof config.data === 'function') { + config.data(data); + } else if (typeof config.data === 'object') { + $.extend(data, config.data); + } + + // Convert data to a flat structure for submission + var flattened = flattenJson(data); + + // Create an iframe + var iframe = $('