Natural Sort not working with the nightly build

Natural Sort not working with the nightly build

Marko76Marko76 Posts: 16Questions: 0Answers: 0
edited January 2014 in General
Hi guys,

I am making a gradebook table and the columns that are displaying student grades look like this: "120pts (87%)." In order to successfully do sorting on these columns I implemented the natural sort referenced in this forum post:

http://datatables.net/forums/discussion/comment/21622

This all works great with version 1.9.4. However there is a bug in 1.9.4. which makes column reordering not work when used in conjunction with fixedColumns. You can see the bug in this video:

http://screencast.com/t/JzlsUercRi7A

I believe it is known bug but basically if you try to move a column all the way next to the fixed column it causes the error. I think I read someplace in your forums that it has something to do with hidden vs. visible columns. In any case I decided to use your nightly builds to try and fixed the issue and indeed the nightly build do take care of this bug. However the code I wrote for natural sort does not work anymore. I was wondering if you can tell me what was changed in the nightly builds that breaks my natural sort code and what do I need to do to fix it. The way I do it now is I overwrite the string-asc and string-desc behavior like this:

[code]jQuery.fn.dataTableExt.oSort['string-asc'] = function (a, b) {
return naturalSort(a, b);
};

jQuery.fn.dataTableExt.oSort['string-desc'] = function (a, b) {
return naturalSort(a, b) * -1;
};[/code]

What do I need to change to make the naturals sort work with the nightly builds?

Replies

  • Marko76Marko76 Posts: 16Questions: 0Answers: 0
    I also see in the notes for nightly that the next version will support sorting based on html 5 data- attributes. Is there any chance you could provide a simple example of how this feature will work so that maybe I could implement this rather than using the natural sort?
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    > I also see in the notes for nightly that the next version will support sorting based on html 5 data- attributes. Is there any chance you could provide a simple example of how this feature will work so that maybe I could implement this rather than using the natural sort?

    Yes - https://github.com/DataTables/DataTables/blob/master/examples/advanced_init/html5-data-attributes.html

    It will be properly documented when it is released.

    Thanks for noting the natural sort issue. I will look into it.

    Allan
  • Marko76Marko76 Posts: 16Questions: 0Answers: 0
    Allan,

    thank you very much for your prompt response. Thanks to your link I did manage to get sorting work via the data-sort attribute. this is great for me since the cell data in my table can have multiple formats based on user settings so defining an underlying sort field is essential for me.

    However updating to nightly build files (jquery.dataTables.js, ColReorder.js and FixedColumns.js) broke the code I wrote that was properly resizing the table when the window is resized. My code for resizing is bellow:

    [code]
    $(window).smartresize(function () {
    var height = CalculateHeight();
    var oSettings = oTable.fnSettings();
    oSettings.oScroll.sY = CalculateDataTableHeight(height);
    oTable.fnAdjustColumnSizing();
    oTable.fnDraw();
    });[/code]

    The CalculateDataTableHeight method basically takes the available height and adjusts it to take into account the footer rows I have in my table. This worked fine before as you can see in this video:

    http://screencast.com/t/JjfjqQ2hXnJO

    However when I update the scripts to the nightly build versions this is not working anymore. Here is the video of that:

    http://screencast.com/t/IqBUNTtE

    Do you have idea why is this happening and what do I need to do to redraw the table if the window size is changed? I looked an number of solutions both here and on Stackoverflow but none of them are working with nightly build. Has something changed with regards to how sScrollY property works?
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Off the top of my head, I don't know I'm afraid. I guess something must have changed, bu DataTables 1.10 has been in development for more than a year with hundreds of commits, and my memory is fuzzy! I'd need to look into it, but it is something that I need to check as I know others also use a similar approach.

    Allan
  • Marko76Marko76 Posts: 16Questions: 0Answers: 0
    Allan,

    thanks for the update. I think for now I will just AJAX reload the entire table container every time the user resizes the screen. It's not very efficient approach but I think that is much less likely to happen than the issue with reordering columns when the 1st column is fixed which the nightly build fixed for me.

    If you find the solution for the issue please let me know... And keep up the good work!!! :)

    Marko
This discussion has been closed.