Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6173453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:34:45+00:00 2026-05-23T23:34:45+00:00

I have a datatable in Grails with several sortable columns. Unfortunately, the sort is

  • 0

I have a datatable in Grails with several sortable columns. Unfortunately, the sort is case-sensitive by default, such that “Zed” is shown before “alice”. So I want to add a custom case-insensitive sort function. I’ll start by sorting the username column in this manner.

I have read about the sortOptions and sortFunction at http://developer.yahoo.com/yui/datatable/ but I can’t seem to get it to work.

I added the following JavaScript to list.gsp:

var caseInsensitiveSortFunction = function(a, b, desc, field) {
    // See http://developer.yahoo.com/yui/datatable/ and look for 'sortFunction'
    // Set this function name as the sortFunction option
    // Deal with empty values
    if (!YAHOO.lang.isValue(a)) {
        return (!YAHOO.lang.isValue(b)) ? 0 : 1;
    } else if (!YAHOO.lang.isValue(b)) {
        return -1;
    }

    return YAHOO.util.Sort.compare(String(a).toLowerCase(), String(b).toLowerCase(), desc);
};

And here is the datatable definition on that same page:

<gui:dataTable id="userTable"
    controller="user" action="listJSON"
    rowsPerPage="20"
    sortedBy="username"
    columnDefs="[
                [key:'username', label:'Username', resizeable: false, sortable: true, sortOptions: { sortFunction: 'caseInsensitiveSortFunction' }],
                [key:'email', label:'Email', resizeable: false, sortable: true],
                [key:'firstName', label:'First Name', resizeable: false, sortable: true],
                [key:'lastName', label:'Last Name', resizeable: false, sortable: true],
                [key:'enabled', label:'Enabled', resizeable: false, sortable: true],
                [key:'accountLocked', label:'Locked', resizeable: false, sortable: true],
                [key:'roleDescription', label:'Role', resizeable: false, sortable: true]
            ]"
    draggableColumns="true"
    rowClickNavigation="true"
    paginatorConfig="[
            template:'{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}',
            pageReportTemplate:'{totalRecords} total record(s)',
            alwaysVisible:true,
            containers:'dt-paginator'
            ]"/>
<div id="dt-paginator" class="yui-skin-sam yui-pg-container"></div> 

Changing the ‘username’ key to the following (sans quotes) does not help.

                [key:'username', label:'Username', resizeable: false, sortable: true, sortOptions: { sortFunction: caseInsensitiveSortFunction }],

Both approaches create the following source. Note that the sortOptions for the username is blank.

            <div id="dt_div_userTable"></div> 
            <script> 
            YAHOO.util.Event.onDOMReady(function () {
                var DataSource = YAHOO.util.DataSource,
                    DataTable  = YAHOO.widget.DataTable,
                    Paginator  = YAHOO.widget.Paginator;

                var userTable_ds = new DataSource('/admin/gpupUser/listJSON?');
                userTable_ds.responseType   = DataSource.TYPE_JSON;
                userTable_ds.connMethodPost=true;
                userTable_ds.responseSchema = {
                    resultsList : 'results',
                    fields      : ["username","email","firstName","lastName","enabled","accountLocked","roleDescription","dataUrl"],
                    metaFields  : {
                        totalRecords: 'totalRecords'
                    }
                };
                userTable_ds.doBeforeCallback = function(oRequest, oFullResponse, oParsedResponse, oCallback) {
                    return GRAILSUI.util.replaceDateStringsWithRealDates(oParsedResponse);
                };

                var userTable_paginator = new Paginator(
                    {'template': '{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}',
'pageReportTemplate': '{totalRecords} total record(s)',
'alwaysVisible': true,
'containers': 'dt-paginator',
'rowsPerPage': 20}
                );

                var registerEditorListener = function(editor, field, url,successCallback,failureCallback) {
                    editor.subscribe("saveEvent", function(oArgs) {
                        GRAILSUI.userTable.loadingDialog.show();
                        var editorCallback = {
                            success: successCallback,
                            failure: function(o) {
                                // revert the cell value
                                GRAILSUI.userTable.updateCell(oArgs.editor.getRecord(), field, oArgs.oldData);
                                // alert user
                                if (failureCallback)
                                  failureCallback(o);
                                else
                                  alert('Received an error during edit: ' + o.responseText);
                            }
                        };
                        YAHOO.util.Connect.asyncRequest('POST', url, editorCallback, 'id=' + oArgs.editor.getRecord().getData('id') + '&field=' + field + '&newValue=' + oArgs.newData);
                    });
                };



                var myColumnDefs = [{'key': 'username',
'label': 'Username',
'resizeable': false,
'sortable': true,
'sortOptions': }, {'key': 'email',
'label': 'Email',
'resizeable': false,
'sortable': true}, {'key': 'firstName',
'label': 'First Name',
'resizeable': false,
'sortable': true}, {'key': 'lastName',
'label': 'Last Name',
'resizeable': false,
'sortable': true}, {'key': 'enabled',
'label': 'Enabled',
'resizeable': false,
'sortable': true}, {'key': 'accountLocked',
'label': 'Locked',
'resizeable': false,
'sortable': true}, {'key': 'roleDescription',
'label': 'Role',
'resizeable': false,
'sortable': true}, {'key': 'dataUrl',
'type': 'dataDrillDown',
'hidden': true}];

                GRAILSUI.userTable = new GRAILSUI.DataTable('dt_div_userTable', myColumnDefs, userTable_ds, '', {
                    initialRequest         : 'max=20&offset=0&sort=username&order=asc&',
                    paginator              : userTable_paginator,
                    dynamicData            : true,
                    sortedBy               : {key: "username", dir: YAHOO.widget.DataTable.CLASS_ASC},
                    'draggableColumns': true,
'selectionMode': 'single',
'rowClickNavigate': false,
'rowClickMode': 'navigate',
'formatter': 'text'
                });
                // Update totalRecords on the fly with value from server
                GRAILSUI.userTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
                    oPayload.totalRecords = oResponse.meta.totalRecords;
                    return oPayload;
                };

                // Set up editing flow
                var highlightEditableCell = function(oArgs) {
                    var elCell = oArgs.target;
                    if(YAHOO.util.Dom.hasClass(elCell, "yui-dt-editable")) {
                        this.highlightCell(elCell);
                    }
                };
                GRAILSUI.userTable.subscribe("cellMouseoverEvent", highlightEditableCell);
                GRAILSUI.userTable.subscribe("cellMouseoutEvent", GRAILSUI.userTable.onEventUnhighlightCell);
                GRAILSUI.userTable.subscribe("cellClickEvent", GRAILSUI.userTable.onEventShowCellEditor);
            });
            </script> 

<div id="dt-paginator" class="yui-skin-sam yui-pg-container"></div>

Is there any way to get the datatable to use a custom sortFunction when configured as a tag?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:34:47+00:00Added an answer on May 23, 2026 at 11:34 pm

    After digging into the code base, I finally realized that the sorting was being done on the server side, so I was able to address the issue there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a datatable with 4 columns A, B, C and D such that
I have a DataTable. I'd like to sort its default view by a column
I have a DataTable that has several DataColumns and DataRow. Now i would like
I have a DataTable which is bound to DataGridView . DataTable has several columns
I have a DataTable that queries out something like below usergroupid...userid......username 1.............1...........John 1.............2...........Lisa 2.............3...........Nathan
I have a DataTable that has a boolean column called [Invalid]. I need to
I have a datatable that has a date column, but I am stumped as
I have a DataTable with 3 columns (a,b,c) and a docx file with the
I have DataTable with the following columns: ClientID date numberOfTransactions price ClientID is of
we have a datatable st with two columns word and binary void replace() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.