prevent emty class attribute added to each cell ( class=" " )

prevent emty class attribute added to each cell ( class=" " )

hirnsaegehirnsaege Posts: 5Questions: 0Answers: 0
edited December 2012 in DataTables 1.9
Dear supporters,
i'm trying to clean up a large data table as much as possible to improve loading and processing performance.
besides the usual optimizations, i also try to clean up the source DOM as much as possible, that is removing unneeded classes etc.
after i have removed almost all classes, i see that datatables adds an emty class attribute to each cell.

So my original DOM is: foo
and datatables processes and creates: foo

I'm wondering if this is any purpose, and if not, if i could prevent doing it, as i think adding lets say 1000x20 attributes to the DOM may take some time in slower browsers ...

I have searched the documentation, but could not find anything about cell classes, only about row classes so far.

thanks for your help
hirnsaege

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Heh - oddly, the empty space class names are due to a performance optimisation for the sorting classes. Its much faster to do it the way DataTables does, although less clean, rather than using hasClass etc. Its a trade off between performance and cleanness. If you want to change it, have a look at the _fnSortingClasses method.

    Allan
  • hirnsaegehirnsaege Posts: 5Questions: 0Answers: 0
    thanks for the reply – if it serves overall performance, i'm just happy with it.
    i was just wondering whether adding the (from my perspective useless) empty class while initializing would cause a delay before the table is "usable", but if it has a purpose, it's okay to me.

    just thinking: would it potentially speed up things if i add the class=" " when creating the table at the server, so datatables does not have to do that job?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    It should only add it to cells which have been sorted in a column. It won't just add it to all cells - as you say, that owl due a performance hit.

    Allan
  • hirnsaegehirnsaege Posts: 5Questions: 0Answers: 0
    okay, that's strange – according to firebug, it adds class=" " to every td in the table, if the td does not have a class="foo" set in the original data. (if so, it changes it to class="foo ") though.

    this is my configuration at the moment:
    [code]
    var oTablename = $('#tablename').dataTable( {
    "bPaginate": false,
    "bLengthChange": false,
    "bStateSave": true,
    "iCookieDuration": 120,
    "bProcessing": true,
    "bSortClasses": false,
    "bAutoWidth": false,
    "aoColumns": [
    {"sWidth": "25%", "bSearchable": false, "bSortable": true},
    {"sWidth": "25%", "bSearchable": false, "bSortable": false},
    {"sWidth": "25%", "bSearchable": true, "bSortable": true},
    {"sWidth": "25%", "bSearchable": false, "bSortable": false},
    ],
    "asStripeClasses": [ ]
    }
    } );
    [/code]

    i have set bSortClasses to false. this way, every td in the table has a class=" " added with initialisation.
    If i set it to true, it every tdhas the class=" " after initialization, and then adds the classes class="sorting_1 " ... to the column cells when they are sorted (as you say), while the rest of the columns (not specifically sorted) is still class=" ".

    sorry if leading you in circles with this ... i'm even not sure if it's a problem at all.

    kind regards
    hirnsaege
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You are right - there is something odd going on there. I wonder if there is a regression in 1.9.4 :-(. Unfortunately I'm away for a few days traveling, but I'll look at this when I get back and determine exactly what is going on.

    Thanks for flagging this up.

    Allan
  • hirnsaegehirnsaege Posts: 5Questions: 0Answers: 0
    thanks for looking into it – no problem if this takes a while ... my IE8 users are used to wait :-)
  • hirnsaegehirnsaege Posts: 5Questions: 0Answers: 0
    anything new in this yet? (no hurry, just interest)
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Not yet sorry. I'll be looking at this as part of the 1.10 development, but that's on hold while I work on some contracts. Hope to get to it at the end of the month.

    Allan
  • DutchSpeedDutchSpeed Posts: 5Questions: 0Answers: 0
    I'm having the same problem.

    Is there any fix yet?

    Thanks in advance.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Not yet. Still on the to-do list.

    Allan
This discussion has been closed.