4

My code is like this : http://jsfiddle.net/oscar11/ebRXw/805/

$(document).ready(function() {
    var table = $('#example').DataTable( {
        "responsive": true
    } );
} );

In my example:

  • Column 0 = Name
  • Column 1 = Position
  • Column 2 = Office

I want to change it to be like this without changing the HTML:

  • Column 0 = Salary
  • Column 1 = Start date
  • Column 2 = Age
3
  • How about changing the HTML? Or do you want change the order without changing the HTML? Commented Oct 15, 2015 at 19:22
  • @Gyrocode.com, Yes, I want change the order without changing the HTML Commented Oct 15, 2015 at 19:28
  • @Gyrocode.com, I need your help. You try to see here : link. Does it modify the Ignited-Datatables Library? Commented Oct 19, 2015 at 13:37

2 Answers 2

7

SOLUTION

Use columns.data to set data source index for each column.

var table = $('#example').DataTable( {
    "responsive": true,
    "columns": [
        { "data": 5 },
        { "data": 4 },
        { "data": 3 },
        { "data": 0 },
        { "data": 1 },
        { "data": 2 }
    ]
} );

Don't forget to adjust table headings in thead section accordingly.

DEMO

See this jsFiddle for code and demonstration.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm sorry. I mean to change the index without changing the order. Whether it can be done?
@mosestoh, that is not possible. You can use name if you don't want to use indexes but that is as far as you can get.
Thank you. I will make another right questions to resolve my issue.
3

You could include the ColReorder plugin and reorder the columns upon initialisation :

$(document).ready(function() {
    var table = $('#example').DataTable( {
        "responsive": true,
        colReorder: {
          order: [5,4,3,0,1,2]
        }
    } );
} );

forked fiddle -> http://jsfiddle.net/8qrqpjsp/

3 Comments

I'm sorry. I mean to change the index without changing the order. Whether it can be done?
@mosestoh, why do you need that? Sounds like a XY problem - guess you are out in a peculiar solution to solve a completely other issue ...?
Thank you. I will make another right questions to resolve my issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.