Exclude data from sort

Exclude data from sort

BenHicksBenHicks Posts: 3Questions: 0Answers: 0
edited July 2011 in General
Is it possible to Exclude certain data from sorting?

example:

I have a column of titles and names, eg: Mr Peter Parker, Miss Lois Lane, Mr Bruce Wane etc..

The data is served from a DB so I cannot modify it.

Can I choose to exclude Mr, Mrs, Miss etc so I can sort the column by first name?

Many thanks for any response in advance.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    yes. in column definitions or columns object (both examples are shown below), set "bSearchable" to false

    http://www.datatables.net/ref
    [code]
    /* Using aoColumnDefs */
    $(document).ready(function() {
    $('#example').dataTable( {
    "aoColumnDefs": [
    { "bSearchable": false, "aTargets": [ 0 ] }
    ] } );
    } );

    /* Using aoColumns */
    $(document).ready(function() {
    $('#example').dataTable( {
    "aoColumns": [
    { "bSearchable": false },
    null,
    null,
    null,
    null
    ] } );
    } );
    [/code]
  • BenHicksBenHicks Posts: 3Questions: 0Answers: 0
    Thanks for the response, I should have been a little more specific - in my case the Title, First name and Lastname are all in the same column (crazy I know for a DB but this is what I have to work with :-s )

    I think what I'm looking for is some sort of filter option to exclude Mr, Mrs etc from that column's sorting, whilst still displaying it.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited July 2011
    define an fnRender function for that column

    [code]
    /* Using aoColumnDefs */
    $(document).ready(function() {
    $('#example').dataTable( {
    "aoColumnDefs": [
    {
    "aTargets": [ 0 ]
    "fnRender": function (oObj) {
    var val = oObj.aData[oObj.iDataColumn]; // get the data of this cell
    val = replace('/^[Mm]rs?\.? +/', '');
    val = replace('/^[Mm]iss +/', '');

    return val; // this is super important. must return string val that becomes the new cell value
    }
    }
    ] } );
    } );
    [/code]

    something like that.
  • BenHicksBenHicks Posts: 3Questions: 0Answers: 0
    Brill, I shall give it a try :) thanks very much for your assistance.
This discussion has been closed.