Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API access from event callbacks undefined #173

Open
bytestream opened this issue Jun 26, 2020 · 2 comments
Open

API access from event callbacks undefined #173

bytestream opened this issue Jun 26, 2020 · 2 comments
Labels

Comments

@bytestream
Copy link
Contributor

$('#table').on('draw.dt', function (settings, json) {
    var api = new $.fn.dataTable.Api(settings),
        rows = api.rows({page: 'current'}).nodes(),
        last = null;

        api.column(1, {page: 'current'}).data().each(function (group, i) {
            if (last !== group) {
                $(rows).eq(i).before('<tr class="group"><td colspan="6"><strong>Group</strong>: ' + group + '</td></tr>');

            last = group;
        }
    });
});
$('#table').dataTable({ /* ... */ });

In the above code upon initialisation the draw event fires but (new $.fn.dataTable.Api(settings)).column(1, {page:'current'}).data() returns undefined while $(this).DataTable().column(1, {page:'current'}).data() returns expected data.

Is this expected?

Presumably something has not properly initialised yet in the settings

@DataTables
Copy link
Collaborator

Nope I wouldn't have expected that. As you say, it sounds like the settings object isn't fully initialised or perhaps it isn't in the array of objects (although I thought that was one of the first things to happen).

Thanks for posting this.

@DataTables DataTables added the bug label Jun 29, 2020
@bytestream
Copy link
Contributor Author

Just in case you need a fiddle https://jsfiddle.net/bytestream/vanLyjfo/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant