Custom reordering of columns

Custom reordering of columns

sureshgantisureshganti Posts: 5Questions: 0Answers: 0
edited August 2011 in Plug-ins
Hi,

I am using datatables and I need Custom reordering of columns in the client side (Not drag and drop of columns). We have a requirement like we need to show all the columns present in the datatable in a optional multiselect and based on the order of the columns selected I need to change the order. Is it possible in the datatable?

Please let me know.

Thanks,
Suresh.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    if you use mDataProp and object-based aaData, you can order them any way you want.

    read http://www.datatables.net/ref#mDataProp
  • sureshgantisureshganti Posts: 5Questions: 0Answers: 0
    Hi,

    Thanks for the immediate response. I am using mDataProp and Objected based data.
    Can you please provide one example how to reorder columns using these.

    Thanks,
    Suresh
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    you could create a master array of arrays to represent the aoColumns (or column defs)

    when user changes the multi-select values, create a new aoColumns object by creating an aoColumns object using the master array but with the order customized, then bDestroy the table and re-initialize it with the new aoColumns.
  • sureshgantisureshganti Posts: 5Questions: 0Answers: 0
    But I have a small doubt here. I hard coded the column title in the table itself. Will it be causing any problem.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited August 2011
    you can override the column titles with values in the aoColumns (using sTitle). so hard-coded HTML won't be an issue.



    [code]
    $(document).ready(function() {
    /* Build the DataTable with third column using our custom sort functions */
    $('#example').dataTable( {
    "aoColumns": [
    { "sTitle": 'NewTitle' } // will over-ride any HTML content in the TH
    ]
    } );
    } );
    [/code]
  • sureshgantisureshganti Posts: 5Questions: 0Answers: 0
    Ok thanks alot. I will try tomorrow and get back to you if I found any issues in resolving it.

    Regards,
    Suresh.
  • sureshgantisureshganti Posts: 5Questions: 0Answers: 0
    Hi,

    Thanks for the post. Its working!!!!!!!!

    Regards,
    Suresh.
This discussion has been closed.