0

I was working on the project and suddenly the DataTable started to remain undefined after initialization, well it doesn't initialize itself either for some reason.

This is how I'm using it:

declare var $;

export ClassName implements OnInit {
    dataTable: any;
    ngOnInit(){
        this.dataTable = $('#table').DataTable({
          processing: true,
          ordering: false,
          pageLength: 10,
          language: this.getLanguages(),
          searching: false,
          dom: 't',
          paging: true,
          columns: comp.getColumns(), // returns columns
          createdRow: ( row, data, dataIndex) => {
            /* code */
          }
        });
    // code doesn't come here
    }
}

The error on the console is;

core.js:5828 ERROR TypeError: Cannot read property 'style' of undefined
    at _fnCalculateColumnWidths (datatables.bundle.js:5601)
    at _fnInitialise (datatables.bundle.js:4715)
    at loadedInit (datatables.bundle.js:1294)
    at HTMLTableElement.<anonymous> (datatables.bundle.js:1306)
    at Function.each (vendors.bundle.js:1290)
    at jQuery.fn.init.each (vendors.bundle.js:1125)
    at jQuery.fn.init.DataTable [as dataTable] (datatables.bundle.js:869)
    at jQuery.fn.init.$.fn.DataTable (datatables.bundle.js:15123)
    at comp.ngOnInit (comp.ts:149)
    at callHook (core.js:3892)

I've searched for it on the web but couldn't find an answer to solve my issue. As I told before, this suddenly became an issue without me changing something about the DataTable..

Thanks in advance people.

1 Answer 1

1

This was happening because there was an error that was occuring inside the comp.getColumns() which held the dataTable from being initialized.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.