HTML5 data-* attributes suggestions and comments.

HTML5 data-* attributes suggestions and comments.

adjenksadjenks Posts: 22Questions: 6Answers: 0

These tags are great, they me to use the same JS for two different pages and set the differences in my markup. I have two suggestions though:
1. Datatables should use a namespace prefix to prevent collision with other libraries in the data- tags, so instead of data-sortable, it would be data-dt_sortable for example.
2. There should be a general purpose tag called data-dt_alloptions which can be used to set every option type all in one tag using JSON. Does this exist already? It would be fabulous. I don't like making millions of data-something tags and would rather just shove a bunch of JSON in a single tag.

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    1) Fair point. It makes the naming a bit more ugly, but I can see why you'd want to do that. Possibly a good idea for an option (i.e. specify your own prefix if you want one).

    2) Currently no there isn't. But you could easily have your own:

    $('#myTable').DataTable( JSON.parse( $('#myTable').data('dt_alloptions') ) );
    

    That's for a single table, you could do the same with a simple loop to keep it generic.

    Allan

  • adjenksadjenks Posts: 22Questions: 6Answers: 0

    Yeah good idea, an optional prefix sounds good.

    I think the config you demonstrated would work for many cases, but the problem is that I need to initialize the table with JavaScript and then use the data-* tags for additional configuration. If I only used the data-* tags I could not include functions, as are needed in the createdCell callbacks and other callback based options.
    This could be alleviated if the functions were called by name and you could just assign it to the name of a function, but that might not be the way to go, it would create extra overhead for every createdCell call, checking if the callback is a string or a function first.

    So, is there a way to add JSON config in addition to the initial configuration in javascript?

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    Yes, JSON and the data-* properties are frustratingly limited in that way. I've not yet decided how to handle it, but it will probably involve a prefix for the function name to be called. It does limit what options can be called is the problem.

    If you want to use functions, at the moment the only way to do it is with Javascript directly (it could be dynamically loaded Javascript), since JSON cannot represent functions.

    Allan

This discussion has been closed.