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

Column reordering breaks types used for sorting #90

Closed
gilthe opened this issue Nov 29, 2024 · 1 comment
Closed

Column reordering breaks types used for sorting #90

gilthe opened this issue Nov 29, 2024 · 1 comment

Comments

@gilthe
Copy link

gilthe commented Nov 29, 2024

This is with a recently downloaded:

 * Included libraries:
 *   JSZip 3.10.1, pdfmake 0.2.7, DataTables 2.1.8, Buttons 3.2.0, Column visibility 3.2.0, HTML5 export 3.2.0, Print view 3.2.0, ColReorder 2.0.4, KeyTable 2.12.1, Scroller 2.4.3

After column reordering, all columns sort like string (the default) even though they were initialized with, e.g., "num". Before reordering, all sorting works as expected.
It took me a while to find this, but in the function:

/**
 * Run finishing activities after one or more columns have been reordered.
 *
 * @param dt DataTable being operated on - must be a single table instance
 */
function finalise(dt) {
    // Cache invalidation. Always read from the data object rather
    // than reading back from the DOM since it could have been
    // changed by a renderer
    dt.rows().invalidate('data');
    // Redraw the header / footer. Its a little bit of a hack this, as DT
    // doesn't expose the header draw as an API method. It calls state
    // saving, so we don't need to here.
    dt.column(0).visible(dt.column(0).visible());
    dt.columns.adjust();
    dt.columns().types(); // !!!!!! ADDED !!!!!!!
    // Fire an event so other plug-ins can update
    var order = dt.colReorder.order();
    dt.trigger('columns-reordered', [
        {
            order: order,
            mapping: invertKeyValues(order)
        }
    ]);
}

The call to rows().invalidate() also invalidates columns, including their types (sType becomes null). To rectify the behavior in my case, I inserted an extra call to columns.types().

AllanJard added a commit to DataTables/DataTablesSrc that referenced this issue Jan 16, 2025
…solved. This could happen after data has been invalidated (e.g. after column reordering).

DataTables/ColReorder#90
AllanJard pushed a commit to DataTables/Dist-DataTables that referenced this issue Jan 16, 2025
…s null when it is sorted, it should be resolved. This could happen after data has been invalidated (e.g. after column reordering).

DataTables/ColReorder#90

Sync to source repo @7bceadf844166e18631bbf022babaf83887d6956
@AllanJard
Copy link
Contributor

Hi - many thanks for this and apologies for the delayed reply. I actually think the issue goes a little deeper and DataTables should resolve the data types for the columns on ordering if needed. I've committed that fix here.

AllanJard pushed a commit to DataTables/Dist-DataTables-DataTables that referenced this issue Jan 16, 2025
…s null when it is sorted, it should be resolved. This could happen after data has been invalidated (e.g. after column reordering).

DataTables/ColReorder#90

Sync to source repo @7bceadf844166e18631bbf022babaf83887d6956
AllanJard pushed a commit to DataTables/Dist-DataTables-Bootstrap that referenced this issue Jan 16, 2025
…s null when it is sorted, it should be resolved. This could happen after data has been invalidated (e.g. after column reordering).

DataTables/ColReorder#90

Sync to source repo @7bceadf844166e18631bbf022babaf83887d6956
AllanJard pushed a commit to DataTables/Dist-DataTables-Foundation that referenced this issue Jan 16, 2025
…s null when it is sorted, it should be resolved. This could happen after data has been invalidated (e.g. after column reordering).

DataTables/ColReorder#90

Sync to source repo @7bceadf844166e18631bbf022babaf83887d6956
AllanJard pushed a commit to DataTables/Dist-DataTables-jQueryUI that referenced this issue Jan 16, 2025
…s null when it is sorted, it should be resolved. This could happen after data has been invalidated (e.g. after column reordering).

DataTables/ColReorder#90

Sync to source repo @7bceadf844166e18631bbf022babaf83887d6956
AllanJard pushed a commit to DataTables/Dist-DataTables-SemanticUI that referenced this issue Jan 16, 2025
…s null when it is sorted, it should be resolved. This could happen after data has been invalidated (e.g. after column reordering).

DataTables/ColReorder#90

Sync to source repo @7bceadf844166e18631bbf022babaf83887d6956
AllanJard pushed a commit to DataTables/Dist-DataTables-Bootstrap4 that referenced this issue Jan 16, 2025
…s null when it is sorted, it should be resolved. This could happen after data has been invalidated (e.g. after column reordering).

DataTables/ColReorder#90

Sync to source repo @7bceadf844166e18631bbf022babaf83887d6956
AllanJard pushed a commit to DataTables/Dist-DataTables-Bootstrap5 that referenced this issue Jan 16, 2025
…s null when it is sorted, it should be resolved. This could happen after data has been invalidated (e.g. after column reordering).

DataTables/ColReorder#90

Sync to source repo @7bceadf844166e18631bbf022babaf83887d6956
AllanJard pushed a commit to DataTables/Dist-DataTables-Bulma that referenced this issue Jan 16, 2025
…s null when it is sorted, it should be resolved. This could happen after data has been invalidated (e.g. after column reordering).

DataTables/ColReorder#90

Sync to source repo @7bceadf844166e18631bbf022babaf83887d6956
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants