From 6c0d935374856d65c74627775e52d552a26768e8 Mon Sep 17 00:00:00 2001 From: CBoland Date: Fri, 24 Nov 2017 14:45:00 -0600 Subject: [PATCH] Updated datatables.net for 1.10.10 Release Notes: https://cdn.datatables.net/1.10.10/ * Created a type for static column render functions. * Implemented $.fn.dataTable.render.text per release notes. * Implemented language.aria.paginate per release notes. * Added test/sample for handling column-visibility event with new parameter. * Implemented order.fixed() method per release notes. --- types/datatables.net/datatables.net-tests.ts | 32 ++++++++- types/datatables.net/index.d.ts | 71 +++++++++++++++++++- 2 files changed, 100 insertions(+), 3 deletions(-) diff --git a/types/datatables.net/datatables.net-tests.ts b/types/datatables.net/datatables.net-tests.ts index af722ab74f..e5cb5184fd 100644 --- a/types/datatables.net/datatables.net-tests.ts +++ b/types/datatables.net/datatables.net-tests.ts @@ -21,7 +21,13 @@ const lang: DataTables.LanguageSettings = { }, aria: { sortAscending: ": activate to sort column ascending", - sortDescending: ": activate to sort column descending" + sortDescending: ": activate to sort column descending", + paginate: { + first: "First", + last: "Last", + next: "Next", + previous: "Previous" + } } }; @@ -98,6 +104,7 @@ let col: DataTables.ColumnSettings = { orderable: true, orderData: 10, orderDataType: "dom-checkbox", + orderFixed: [[0, 'asc'], [1, 'desc']], orderSequence: ['asc', 'desc'], render: 1, searchable: true, @@ -118,6 +125,20 @@ col = { data: colDataFunc, render: colRenderFunc, }; +col = { + data: "salary", + render: $.fn.dataTable.render.number('\'', '.', 0, '$'), +}; +col = { + data: "url", + render: $.fn.dataTable.render.text(), +}; +col = { + orderFixed: { + pre: [[0, 'asc'], [1, 'desc']], + post: [[0, 'asc'], [1, 'desc']] + } +}; //#endregion "Column" @@ -135,6 +156,7 @@ let colDef: DataTables.ColumnDefsSettings = { orderable: true, orderData: 10, orderDataType: "dom-checkbox", + orderFixed: [[0, 'asc'], [1, 'desc']], orderSequence: ['asc', 'desc'], render: 1, searchable: true, @@ -353,6 +375,9 @@ let order_set = dt.order([0, "asc"]); order_set = dt.order([0, "asc"], [1, "desc"]); // TODO: Fíx that order_set = dt.order([[0, "asc"], [1, "desc"]]); +const fixed_get: DataTables.ObjectOrderFixed = dt.order.fixed(); +const fixed_set: DataTables.Api = dt.order.fixed({pre: [0, "asc"], post: [1, "desc"]}); + const orderListerner = order_set.order.listener("node", 1, () => { }); const page_get = dt.page(); @@ -791,6 +816,11 @@ dt.columns.adjust().draw(false); // adjust column sizing and redraw dt.columns().every(() => { }); dt.columns().every((colIdx, tableLoop, colLoop) => { }); +$('#example').on('column-visibility.dt', (e: object, settings: DataTables.Settings, column: number, state: boolean, recalc: boolean | undefined) => { + const widthRecalced = (recalc || recalc === undefined); + console.log(`Column ${column} has changed to ${(state ? 'visible' : 'hidden')} and width ${(widthRecalced) ? 'was' : 'was not'} recalculated.`); +}); + //#endregion "Methods-Column" //#region "Methods-Row" diff --git a/types/datatables.net/index.d.ts b/types/datatables.net/index.d.ts index 7cd4b8589b..cdddc98789 100644 --- a/types/datatables.net/index.d.ts +++ b/types/datatables.net/index.d.ts @@ -1,6 +1,9 @@ // Type definitions for JQuery DataTables 1.10 // Project: http://www.datatables.net -// Definitions by: Kiarash Ghiaseddin , Omid Rad , Armin Sander +// Definitions by: Kiarash Ghiaseddin +// Omid Rad +// Armin Sander +// Craig Boland // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 @@ -329,6 +332,16 @@ declare namespace DataTables { (order?: Array<(string | number)> | Array>): Api; (order: Array<(string | number)>, ...args: any[]): Api; + /** + * Get the fixed ordering that is applied to the table. If there is more than one table in the API's context, + * the ordering of the first table will be returned only (use table() if you require the ordering of a different table in the API's context). + */ + fixed(): ObjectOrderFixed; + /** + * Set the table's fixed ordering. Note this doesn't actually perform the order, but rather queues it up - use draw() to perform the ordering. + */ + fixed(order: ObjectOrderFixed): Api; + /** * Add an ordering listener to an element, for a given column. * @@ -1085,6 +1098,14 @@ declare namespace DataTables { */ isDataTable(table: string): boolean; + /** + * Helpers for `columns.render`. + * + * The options defined here can be used with the `columns.render` initialisation + * option to provide a display renderer. + */ + render: StaticRenderFunctions; + /** * Get all DataTable tables that have been initialised - optionally you can select to get only currently visible tables and / or retrieve the tables as API instances. * @@ -1125,6 +1146,42 @@ declare namespace DataTables { ext: ExtSettings; } + interface ObjectColumnRender { + display(d?: number | string | object): string | object; + } + + interface ObjectOrderFixed { + /** + * Two-element array: + * 0: Column index to order upon. + * 1: Direction so order to apply ("asc" for ascending order or "desc" for descending order). + */ + pre?: any[]; + /** + * Two-element array: + * 0: Column index to order upon. + * 1: Direction so order to apply ("asc" for ascending order or "desc" for descending order). + */ + post?: any[]; + } + + interface StaticRenderFunctions { + /** + * Will format numeric data (defined by `columns.data`) for display, retaining the original unformatted data for sorting and filtering. + * + * @param thousands Thousands grouping separator. + * @param decimal Decimal point indicator. + * @param precision Integer number of decimal points to show. + * @param prefix Prefix (optional). + * @param postfix Postfix (/suffix) (optional). + */ + number(thousands: string, decimal: string, precision: number, prefix?: string, postfix?: string): ObjectColumnRender; + /** + * Escape HTML to help prevent XSS attacks. It has no optional parameters. + */ + text(): ObjectColumnRender; + } + interface StaticUtilFunctions { /** * Escape special characters in a regular expression string. Since: 1.10.4 @@ -1563,6 +1620,15 @@ declare namespace DataTables { */ orderDataType?: string; + /** + * Ordering to always be applied to the table. Since 1.10 + * + * Array type is prefix ordering only and is a two-element array: + * 0: Column index to order upon. + * 1: Direction so order to apply ("asc" for ascending order or "desc" for descending order). + */ + orderFixed?: any[] | ObjectOrderFixed; + /** * Order direction application sequence. Since: 1.10 */ @@ -1571,7 +1637,7 @@ declare namespace DataTables { /** * Render (process) the data for use in the table. Since: 1.10 */ - render?: number | string | ObjectColumnData | FunctionColumnRender; + render?: number | string | ObjectColumnData | FunctionColumnRender | ObjectColumnRender; /** * Enable or disable filtering on the data in this column. Since: 1.10 @@ -1727,6 +1793,7 @@ declare namespace DataTables { interface LanguageAriaSettings { sortAscending: string; sortDescending: string; + paginate?: LanguagePaginateSettings; } //#endregion "language-settings"