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

No initialization #96

Closed
rebendajirijr opened this issue Oct 21, 2014 · 7 comments
Closed

No initialization #96

rebendajirijr opened this issue Oct 21, 2014 · 7 comments

Comments

@rebendajirijr
Copy link

Cannot initialize plugin like this way:

$('.table').each(function() {
    var table = $(this).DataTable();
    yadcf.init(table, [
        ... // column definition
    ]);
});

init function expects some defined selector, which obviously is unknown (if I dump instance.selector it's an empty string so no initialization occurs.

@rebendajirijr rebendajirijr changed the title Failed' No initialization Oct 21, 2014
@vedmack
Copy link
Owner

vedmack commented Oct 21, 2014

And how about dropping the loop and calling the Datatable on '.table' selector?

@rebendajirijr
Copy link
Author

@vedmack Yes, this could be the simplest way, but sometimes the loop is more readable to me especially when there is some more 'tricky' stuff inside it. For now, I simply re-query the element by ID so selector is known.

@Oliboy50
Copy link

👍
Definitely need a fix for this.

FYI, $(this).dataTable().yadcf(); won't work either.

@Pyreweb
Copy link
Contributor

Pyreweb commented Feb 12, 2016

Hey, just a little simple solution, for reference;
It add an ID where there isn't one, so the selector is happy.

$('.table').each(function() {
    var selector = $(this).attr('id'),
        table;

    if (typeof (selector) === 'undefined') {
        selector = String.fromCharCode(65 + Math.floor(Math.random() * 26))  + Date.now();
        $(this).attr('id', selector);
    }
    table = $('#' + selector).DataTable(
     ....

(the random string on selector came from http://stackoverflow.com/a/6860962)

@taarimalta
Copy link

$(document.getElementById('example')).DataTable() did not work. Had to do $('#example').DataTable()

@McNetic
Copy link

McNetic commented Jul 25, 2017

That's not an enhancement, but a serious bug. Took me about 3-4 hours to figure this out. I have a jquery object, I assume I can apply jquery methods on it. Datatable works just fine, but yadcf fails silently, without any indication of the error.
Most of the times, it's obvious where the jquery object comes from, so (if you know you can only work on "selected" objects), you can find the error, but that's not always the case. You should really drop any reference to the selector property....

@vedmack
Copy link
Owner

vedmack commented Dec 3, 2018

Well apparently this issue was fixed long time ago :) just checked it and it works just fine, here a working jsfiddle... http://jsfiddle.net/vedmack/05dtpk1s/20/

@vedmack vedmack closed this as completed Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants