// Type definitions for jquery.dynatable v0.3.1 // Project: http://www.dynatable.com/ // Definitions by: François Massart // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// interface JQuery { /** * @constructor */ dynatable: JQueryDynatable.Dynatable; } /** Static members of jQuery (those on $ and jQuery themselves) */ interface JQueryStatic { /** * Global dynatable plugin setting defaults * * @param options The configuration options to be set globally */ dynatableSetup(options: JQueryDynatable.Options): void; } declare namespace JQueryDynatable { interface Features { /** * Enable the pagination feature * * @default true */ paginate?: boolean; /** * Enable the sorting feature * * @default true */ sort?: boolean; /** * Enable the pushState feature * Used to update the page URL parameters and cache the query result for the browser's forward- and back-buttons * * @default true */ pushState?: boolean; /** * Enable the search feature * * @default true */ search?: boolean; /** * Enable the recordCount feature * When pagination is enabled, dynatable will also show the currently displayed records and the total number of records * * @default true */ recordCount?: boolean; /** * Enable the perPageSelect feature * The perPageSelect will insert a form control filled with the options from `perPageOptions` * * @default true */ perPageSelect?: boolean; } interface Column { index: number; label: string; /** * Determined by the `data-dynatable-column` or using the `defaultColumnIdStyle` * * @example * // Using the `defaultColumnIdStyle` of `camelCase` * // `Favorite Music` would be translated into the id `favoriteMusic` */ id: string; /** * Function that returns the cell data to be written inside the cell * * @param record A data object representing the current line of data * @return The data for the current cell * * @example * function exampleAttributeWriter(record) { * return record[this.id]; * }; */ attributeWriter: (record: any) => any; /** * Function that interprets the cell html data in order to convert it into data * * @param cell A html node of the target cell * @param record A data object representing the current line of data * @return the html content for the current cell * * @example * function exampleAttributeReader(cell, record) { * return $(cell).html(); * }; */ attributeReader: (cell: Element, record: any) => string; /** List of ids for sorting, generated by the plugin, can be tweaked by using `data-dynatable-sorts` */ sorts: Array; hidden: boolean; /** * Detected internally by dynatable. * Possible values are: * * @enum('left', 'right', 'center', 'justify', 'initial', 'inherit') */ textAlign: string; } interface Table { /** * By default, dynatable converts headings to JSON attribute names using: * * @enum('camelCase', 'trimDash', 'dashed', 'underscore', 'lowercase') * @default 'camelCase' * @see http://www.dynatable.com/#converting-attribute-names * * @example * // Given the html `Favorite Music` column header * // `camelCase` would translate it to id `favoriteMusic` * // `trimDash` would translate it to id `Favorite-Music` * // `dashed` would translate it to id `favorite-music` * // `underscore` would translate it to id `favorite_music` * // `lowercase` would translate it to id `favorite music` */ defaultColumnIdStyle?: string; /** Generated internally by the plugin, will be reset by the DomColumns at init */ columns?: Array; /** * Selector used by dynatable in order to find the table header row * * @default 'thead tr' */ headRowSelector?: string; /** * Selector used by dynatable in order to find the table body rows * * @default 'tbody tr' */ bodyRowSelector?: string; /** * Optional classname that can be added by dynatable to the header cells * * @default null */ headRowClass?: string; } interface Inputs { /** * Allows you to provide an array of jQuery objects which point to our filter inputs. * The inputs musts have a name attribute value matching a columnId in order to work. * Input values must strictly match the data from the cell... * Searching for "Lux" won't show "Luxembourg" event if it starts if the same letters! * * @default null * @see http://www.dynatable.com/#querying * * @example * $('#search-year') */ queries?: JQuery; /** * @todo Find out how this `inputs.sorts` setting is useful + show an example * @default null * @see http://www.dynatable.com/#sorting */ sorts?: any; /** * Allows you to define the accepted modifier keys to trigger a multisort action * * @default ['ctrlKey', 'shiftKey', 'metaKey'] * @see https://en.wikipedia.org/wiki/Modifier_key */ multisort?: Array; /** * @todo Find out how this `inputs.page` setting is useful + show an example * @default null */ page?: any; /** * The events attached to the search/filtering inputs elements * * @default 'blur change' */ queryEvent?: string; /** * The jQuery object pointing to a target where to insert the recordCount html * * @default null * * @example * $('#chart-status-text') */ recordCountTarget?: JQuery; /** * Determines where the recordCount is inserted * * @enum('before', 'after') * @default 'after' * @see http://api.jquery.com/category/manipulation/dom-insertion-outside/ */ recordCountPlacement?: string; /** * The target inside next to which the pagination block will be inserted (before or after). * You can use a selector string, an Element or a JQuery. * * @default null */ paginationLinkTarget?: string|Element|JQuery; /** * Determines where the pagination links are inserted * * @enum('before', 'after') * @default 'after' * @see http://api.jquery.com/category/manipulation/dom-insertion-outside/ */ paginationLinkPlacement?: string; /** * The classname to be injected on the `
    ` containing the pagination * * @default 'dynatable-pagination-links' */ paginationClass?: string; /** * The classname to be injected on every pagination link * * @default 'dynatable-page-link' */ paginationLinkClass?: string; /** * The classname to be injected on the previous page link * * @default 'dynatable-page-prev' */ paginationPrevClass?: string; /** * The classname to be injected on the next page link * * @default 'dynatable-page-next' */ paginationNextClass?: string; /** * The classname to be injected on the current page link * * @default 'dynatable-active-page' */ paginationActiveClass?: string; /** * The classname to be injected on the disabled page links * * @default 'dynatable-disabled-page' */ paginationDisabledClass?: string; /** * Text content for the previous page link * * @default 'Previous' */ paginationPrev?: string; /** * Text content for the next page link * * @default 'Next' */ paginationNext?: string; /** * Define the number of page number links shown inside the pagination * * @default [1,2,2,1] */ paginationGap?: Array; /** * The target next to which the search block will be inserted (before or after). * You can use a selector string, an Element or a JQuery. * * @default null */ searchTarget?: string|Element|JQuery; /** * Determines where the search field is inserted * * @enum('before', 'after') * @default 'before' * @see http://api.jquery.com/category/manipulation/dom-insertion-outside/ */ searchPlacement?: string; /** * Text preceding the search field * * @default 'Search: ' */ searchText?: string; /** * The target next to which the per page pagination block will be inserted (before or after). * You can use a selector string, an Element or a jQuery object. * * @default null */ perPageTarget?: string|Element|JQuery; /** * Determines where the perPage menu is inserted * * @enum('before', 'after') * @default 'before' * @see http://api.jquery.com/category/manipulation/dom-insertion-outside/ */ perPagePlacement?: string; /** * Text content preceding the items per page ` */ create(): JQuery; /** Set up the pagination per page */ init(): void; /** * Check if the paginate feature is enabled in `settings.features` * * @return A boolean */ initOnLoad(): boolean; /** * Set the new value for the pagination per page * * @param number The new number of items visible per page * @param skipResetPage By default (false) it sends you to page 1 */ set(number: number, skipResetPage?: boolean): void; } interface ProcessingIndicator { /** Insert the processing indicator inside the page */ attach(): void; /** * Generate the html markup for the processing indicator * * @return A jQuery object containing the generated html */ create(): JQuery; /** Hide the processing indicator */ hide(): void; /** Set up the processing indicator */ init(): void; /** * Position the processing indicator at the center * * @return A jQuery object containing the processing indicator */ position(): JQuery; /** Show the processing indicator */ show(): void; } interface Queries { /** * Add a new condition in the queries * * @param name The key for for the query * @param value The value we wish to find * @return A reference to the related Dynatable object */ add(name: string, value: any): Dynatable; /** functions object for Queries */ functions: QueriesFunctions; /** Set up the initial search parameters */ init(): void; /** * Check if search feature is enabled * * @return A boolean if search feature is enabled */ initOnLoad(): boolean; /** * Remove the query from the dataset * * @param name The key for for the query to be removed * @return A reference to the related Dynatable object */ remove(name: string): Dynatable; /** Run a search with all the saved queries */ run(): any; /** * Shortcut for performing simple query from built-in search * * @param q The value that will be searched for */ runSearch(q: any): void; /** Set up the input fields for creating queries */ setupInputs(): void; } interface QueriesFunctions { /** * Search in all of the properties of the provided single record * * @param record A data object with all the properties of the current line * @param queryValue The researched value * @return A boolean indicating if a match was found */ search(record: any, queryValue: string): boolean; } interface Records { /** * Count records from table * * @return The length of the records Array */ count(): number; /** * Get initial recordset to populate table * if ajax, call ajaxUrl * otherwise, initialize from in-table records * * @return An Array with the records */ getFromTable(): Array; /** Create and init the records */ init(): void; /** * Check if ajax feature is enabled * * @return A boolean if ajax feature is enabled */ initOnLoad(): boolean; /** * Get the first and the last indexes based on current page and number of items per page * * @return An Array with the first index ([0]) and the last index ([1]) */ pageBounds(): Array; /** Update the records with the new page */ paginate(): void; /** Reset the records */ resetOriginal(): void; /** * Call the appropriated sort function * * @return The number (-1, 0 or +1) representing the comparison */ sort(): number; /** * Merge ajax response json with cached data including (meta-data and records) * * @param data The new data */ updateFromJson(data: any): void; } interface RecordsCount { /** Insert the record count inside the page */ attach(): void; /** * Generate the html markup for the record count * * @return A jQuery object containing the generated html */ create(): JQuery; /** Create and init the records count */ init(): void; /** * Check if recordCount feature is enabled * * @return A boolean if recordCount feature is enabled */ initOnLoad(): boolean; } interface Settings { dataset: Dataset; features: Features; inputs: Inputs; params: Params; readers: Readers; table: Table; writers: Writers; } interface Sorts { /** * Add a new sort in sortKeys * * @param attr The key for for the sorting * @param direction The sorting direction (-1 or +1) * @return A reference to the related Dynatable object */ add(attr: string, direction: number): Dynatable; /** Remove all the sortKeys */ clear(): void; /** functions object for Sorts */ functions: SortsFunctions; /** * Try to intelligently guess which sort function to use based on the type of attribute values. * * @param a The first record * @param b The second record * @param attr The key of the property * @return A string containing one of the types ('string' or 'number') */ guessType(a: any, b: any, attr: string): string; /** Create and init the sorts */ init(): void; /** * Check if sort feature is enabled * * @return A boolean if sort feature is enabled */ initOnLoad(): boolean; /** * Remove a sort attribute from the sortKeys * * @param attr The key to be removed from the sorting * @return A reference to the related Dynatable object */ remove(attr: string): Dynatable; } interface SortsFunctions { /** * Sorting between 2 numbers * * @param a The first record * @param b The second record * @param attr The key of the property * @param direction The number describingthe order: ASC (+1), DESC (-1) or none (0) * @return The number (-1, 0 or +1) representing the comparison */ number(a: any, b: any, attr: string, direction: number): number; /** * Restores the original order we had... * * @param a The first record * @param b The second record * @return The number (-1, 0 or +1) representing the comparison */ originalPlacement(a: any, b: any): number; /** * Sorting between 2 strings * * @param a The first record * @param b The second record * @param attr The key of the property * @param direction The number describingthe order: ASC (+1), DESC (-1) or none (0) * @return The number (-1, 0 or +1) representing the comparison */ string(a: any, b: any, attr: string, direction: number): number; } interface SortsHeaders { /** * Inject the arrow down inside the $link * * @param $link The jQuery object to be used */ appendArrowDown($link: JQuery): void; /** * Inject the arrow up inside the $link * * @param $link The jQuery object to be used */ appendArrowUp($link: JQuery): void; /** Go through each cell and call `attachOne` */ attach(): void; /** * If sorting is allowed for the provided cell, it injects the hml generated by `create` * * @param cell The cell Element to be parsed */ attachOne(cell: Element): void; /** * Generate the html markup to be inserted inside the header of the sortable column * * @param cell An Element which point to the cell in the header row * @return A jQuery object containing the markup of the link */ create(cell: Element): JQuery; /** Create and init the sorts */ init(): void; /** * Check if sort feature is enabled * * @return A boolean if sort feature is enabled */ initOnLoad(): boolean; /** Remove all the sort headers from the table */ removeAll(): void; /** Remove all arrows Elements from the table */ removeAllArrows(): void; /** * Remove the arrow found inside the provided $link * * @param $link The jQuery object containing the `` markup in the sortable headers */ removeArrow($link: JQuery): void; /** * Remove the link generated by dynatable inside the sortable header * and restore its original html content * * @param cell The cell Element that will be parsed */ removeOne(cell: Element): void; /** * @todo learn more about this method and document it * * @param $link The jQuery object to be used * @param column The Column object that will be used * @return A boolean which is true if supplied test function passes for ALL items in an array */ sortedByColumn($link: JQuery, column: Column): boolean; /** * Inspect the settings to determine the order to use * * @param column The Column object that will be used * @return A number (-1 or +1) describing the order to use (DESC or ASC) */ sortedByColumnValue(column: Column): number; /** * Refresh the [multi] sorting of the dataset * * @param $e The event object (of the click on the table sortable header) * @param $link The header link * @param column The Column object to be sorted */ toggleSort(e: Event, $link: JQuery, column: Column): void; } interface State { /** Set up a listener for popstate event on window */ init(): void; /** * Check if pushState option is true, and if browser supports it * * @return A boolean */ initOnLoad(): boolean; /** * Handler for the popstate event * * @param event The native popstate event */ pop(event: Event): void; /** * Update the URL data using pushState * * @param data An object with the parameters we want to push */ push(data: Object): void; } interface Dynatable { /** * Initialize Dynatable plugin * * @param options An optional object that allow you to change the default configuration options */ (options?: Options): JQuery; /** * Each dynatable instance inherits from this, * set properties specific to instance * * @param element The html node to be used by dynatable * @param options The JQueryDynatable.Options object which contains all the settings * @return A reference to the current and brand new dynatable object */ init(element: Element, options: Options): Dynatable; /** * Call the process method on all the components of this dynatable * * @param skipPushState A boolean allowing to skip the update the query string in the URL */ process(skipPushState?: boolean): void; /** The `element` encapsulated inside a jQuery object */ $element: JQuery; /** The `dom` API */ dom: DOM; /** The `domColumns` API */ domColumns: DOMColumns; /** The native element on which the dynatable plugin was called */ element: Element /** The `inputsSearch` API */ inputsSearch: InputsSearch; /** The `paginationLinks` API */ paginationLinks: PaginationLinks; /** The `paginationPage` API */ paginationPage: PaginationPage; /** The `paginationPerPage` API */ paginationPerPage: PaginationPerPage; /** The `processingIndicator` API */ processingIndicator: ProcessingIndicator; /** The `queries` API */ queries: Queries; /** The `records` API */ records: Records; /** The `recordsCount` API */ recordsCount: RecordsCount; /** The `settings` API */ settings: Settings; /** The `sorts` API */ sorts: Sorts; /** The `sortsHeaders` API */ sortsHeaders: SortsHeaders; /** The `state` API */ state: State; } } //declare var dynatable: JQueryDynatable.Dynatable;