Case insensitive sort

Case insensitive sort

plwplw Posts: 34Questions: 13Answers: 0

Is there a way of of doing a case insensitive sort please. There must be lots of people who need it so I can't believe it isn't possible

Answers

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    The default behaviour is case insensitive searches - for example, type "ashton" on the home page table. If you want to disable it, you can use search.caseInsensitive,

    Colin

  • plwplw Posts: 34Questions: 13Answers: 0
    edited June 2022

    I know and I wish it wasn't :(. I just have and it still hasn't made any difference (:

    $(document).ready(function () { 
                   var groupColumn = 4;
                   $("#DTable").dataTable({ 
                       "search": {
                        "caseInsensitive": true
                          },
                       "pageLength": 30,
                       autoWidth: false,
                       columnDefs: [
                            { type: 'natural-nohtml', targets: '0' },
                           { type: 'natural-ci', targets: '1' },
                            { visible: false, targets: groupColumn }
                        ],
                      
                       "lengthMenu": [ 10, 25, 30, 50, 75, 100 ],
                       "bFilter": false,
                       "aaSorting": [[ 0, 'asc' ]],
                       "aoColumns": [ 
                           { "bSortable": true },                       
                           { "bSortable": true },                     
                           { "bSortable": true },
                           { "bSortable": true },
                           { "bSortable": false }
                       ],
                       drawCallback: function (settings) {
                        var api = this.api();
                        var rows = api.rows({ page: 'current' }).nodes();
                        var last = null;
                        var TheRowCount = 1;
                        api
                            .column(groupColumn, { page: 'current' })
                            .data()
                            .each(function (group, i) {
                                if (last !== group) {
                                    if (TheRowCount == 1) {
                                        $(rows)
                                            .eq(i)
                                            .before('<tr class="group"><td colspan="4" bgcolor="#ffffcc">' + group + '</td></tr>');
                                    }
                                    else {
                                        $(rows)
                                            .eq(i)
                                            .before('<tr class="group"><td colspan="4" bgcolor="#ffffcc"><hr style="padding: 0px; margin: 0px; background-color: black; border: 0px; height: 2px;">' + group + '</td></tr>');
                                    }
                                    last = group;
                                }
                                TheRowCount++;
                            });
                    },
                   });
               });      
    

    I am stuck

    Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    The default behaviour is case insensitive searches

    Do you actually want case sensitive?
    "caseInsensitive": true doesn't change anything. It's the default.

  • plwplw Posts: 34Questions: 13Answers: 0

    I am trying to sort not search and nothing I have tried makes any Difference.

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Ah sorry, I misread that to be "search", not "sort" - apologies. But that said, sorts also are case-insensitive - see here ("ashton cox"). You can use the case-sensitive sorting plugin if you don't want that behaviour.

    Colin

  • plwplw Posts: 34Questions: 13Answers: 0

    I have just realised that sorted out my Sort Problem as well anyway so thanks for you suggestion. I thought you must have misread it as search but it worked - hurray

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    Correct - DataTables sorting is case-insensitive by default as shown in the source here.

    There is an exception to that though - if you are using server-side processing, then it is up to the server what ordering is applied. Some databases will be case-sensitive by default.

    Allan

Sign In or Register to comment.