Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module dataTable {
- export class dataTableClass {
- applyTable(tableIdString: string) : void {
- (<any>$(tableIdString))
- .DataTable({
- scrollY: 1000,
- scrollX: true,
- scrollCollapse: true,
- paging: false,
- searching: false,
- fixedHeader: true,
- fixedColumns: {
- leftColumns: 1
- }
- });
- }
- dataTableExists(tableIdString: string): boolean {
- return (<any>$.fn.DataTable.isDataTable(tableIdString));
- }
- applyDatatableIfTableExists(retryCount: number, elementId: string): void {
- if (!elementId) {
- console.warn("table id not defined.");
- return;
- }
- if (!retryCount) {
- retryCount = 0;
- } else if (retryCount > 100) {
- console.warn("could not convert table to dataTable.");
- return;
- }
- window.setTimeout(() => {
- var tableIdString = "#" + elementId;
- if ((<any>$(tableIdString)).length <= 0) {
- this.applyDatatableIfTableExists(++retryCount, elementId);
- } else {
- if (this.dataTableExists(tableIdString)) {
- debugger;
- (<any>$(tableIdString)).DataTable({ retrieve: true }).destroy(); // <-- issue here. it seems to restore old data to the now-datatable-less table
- }
- window.setTimeout(() => {
- this.applyTable(tableIdString);
- if (!this.dataTableExists(tableIdString)) {
- this.applyDatatableIfTableExists(++retryCount, elementId);
- }
- }, 250);
- if (!(<any>$(tableIdString)).hasClass(".dataTable")) {
- (<any>$(tableIdString)).addClass(".dataTable");
- }
- }
- }, 250);
- }
- applyDataTable(id) {
- this.applyDatatableIfTableExists(0, id);
- }
- }
Add Comment
Please, Sign In to add comment