How table setting are applied?

How table setting are applied?

xtech_devxtech_dev Posts: 25Questions: 11Answers: 0

I'm tying to change .data option of a single column for already initialized data table. I see that settings passed during initialization are store inside:

$('table').DataTable().settings()[0]

After loading table with data i do the following:

$('#mytable').DataTable().settings()[0].aoColumns[myindex].data = 'otherThanBeforeColumn';
$('#mytable').DataTable().settings()[0].aoColumns[myindex].mData = 'otherThanBeforeColumn';

Then i'm fetching new data, clearing the table, and adding new rows:

dataTable = tableTag.DataTable();
dataTable.rows().remove();
dataTable.rows.add(data).draw();

But column of 'myindex' still takes data from property defined during initialization. Why it does respects new settings value? Is there an internal cache for already initialized settings? If so how can i access it?

It MAn

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    As the documentation for settings() says:

    The information in this object is generally considered to be private and should not be used directly

    The settings object is not writable. You can get data from it if you really must, but for setting values you need to use the API. There is currently no option to change the data point for a column. You'd need to re-initialise the table.

    Allan

  • MSLtdMSLtd Posts: 56Questions: 5Answers: 4

    Hello @xtech_dev are you trying to change what information from the database is displayed in the column?
    If so, modifying the PHP scripts may be necessary to achieve this.

  • xtech_devxtech_dev Posts: 25Questions: 11Answers: 0
    edited July 2018

    It seems faster (with better performance) will be to destroy and reinitialize the table?

    Generally I'm not afraid to implement runtime column add or remove extension, but don't now if I will find access to internal engine of DataTables.

    In case of destroying the table will state restore work?

    It Man

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    If the number of columns are the same, then yes. If they aren't, then DataTables has no idea where the new columns have been added or removed, so the old state is thrown away.

    Allan

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    p.s. This is where DataTables makes use of the data property for the column - caching functions used to get and set values. You could in theory do that again and then invalid the data for the row - but it isn't something I've tried myself. You'd need to split that out into a separate function as well so it is callable again since at the moment it is embedded in the add column methods.

    Allan

This discussion has been closed.