I have a column which has suffix m in it. Any way to remove m and process data for sorting?

I have a column which has suffix m in it. Any way to remove m and process data for sorting?

techaddict009techaddict009 Posts: 7Questions: 1Answers: 0

Is pre-processing of column available? So that m can be removed before processing. (Not from display just for sorting purpose).

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Sure - use columns.render.

    Allan

  • techaddict009techaddict009 Posts: 7Questions: 1Answers: 0

    Seriously I am not getting how to use it. Seems like there is need for proper examples. I just checked this example : http://www.datatables.net/examples/advanced_init/column_render.html

    I couldnt get how to use it my case!

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    edited October 2014

    Assuming I understand correctly, then:

    {
      data: 'myPropertyWithMPostfix',
      render: function ( data, type, row ) {
        return data.substr( 0, data.length-1 );
      }
    }
    

    i.e strip the last character off the data. (edit When I wrote this originally I striped a prefix, rather than postfix).

    If that isn't want you meant, please clarify with a link to a test case showing the issue.

    Allan

  • techaddict009techaddict009 Posts: 7Questions: 1Answers: 0

    Yes you have understood it correctly.

    But One query how to apply this only to specific column say column no 11 (Starting the count from 0).

    Table looks similar to this: http://datatables.net/examples/basic_init/zero_configuration.html

    I am using zero configuration. Want to apply the rendering thing to column 11 which has m in the end and rest normal integer. ex: 1m, 2m, 4m, etc. Sorting to be done only on 1, 2, 4,etc.

  • techaddict009techaddict009 Posts: 7Questions: 1Answers: 0

    Thanks in advance. And for quick responses.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Use the columnDefs.targets option to apply it to a specific column, or set of columns.

    Allan

  • techaddict009techaddict009 Posts: 7Questions: 1Answers: 0
    edited October 2014

    Sorry I was using older version of data tables which was causing the issue.

    So now my issue is. for sorting is done the way i want but m is getting removed from display. I just want m to be removed from sorting logic not from the front end.

  • techaddict009techaddict009 Posts: 7Questions: 1Answers: 0

    Found the fix. Need to use if condition on type=="sort"

    Thanks @Allan for all your support.

    Hope someone writes a simple guide for beginners like me.

This discussion has been closed.