The user-select event only works if its attached AFTER the DT table gets initialized

The user-select event only works if its attached AFTER the DT table gets initialized

jLinuxjLinux Posts: 981Questions: 73Answers: 75

I seem to be having an issue with the new user-select. I typically add the .on( 'event', functionToExecute ) code to the tables jQuery event before the DT instance is initiated. Thats because thats the only way that some of the events will work (EG: I think the init.dt wont work if its attached to the DT instance after its initiated.

However, when the user-select is attached to the table before the DataTables instance gets initiated, it doesn't seem to work.

Example of what I mean, this will not work:

$('#example-2')
.on( 'user-select', userSelectEventCb )
.DataTable({
    select: 'multi'
})

However, this will work:

$('#example-1')
.DataTable({
    select: 'multi'
})
.on( 'user-select', userSelectEventCb )

I created an JSBin example here, you can view the console output to see that it doesn't work if the event is attached to the tables jQuery instance before the DT is initialized.

It makes perfect sense that some of the DT events need to be attached either before or after DT is initialized (EG: again, the init.dt wouldn't make sense to be attached after DT is already initialized), but the user-select should work either way, shouldn't it?

Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,813Questions: 1Answers: 10,517 Site admin
    Answer ✓

    Looks like you forgot the .dt namespace: http://live.datatables.net/vamulagu/2/edit .

    All DataTables related events are triggered with a namespace, which the on() method will add automatically. But if you add the events using $().on(), you need to add the namespace yourself.

    Allan

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Well don't I feel like an idiot, lol.

    Thanks!

  • allanallan Posts: 63,813Questions: 1Answers: 10,517 Site admin

    Pfft. That's nothing. I've just found three bugs today as "already implemented", that I had only just opened in the last few weeks. Next time I say "can't do that" (other than wild card events, which you can't ;-) ), question me...!

    Allan

This discussion has been closed.