2

I'm trying to make a table and need to do something like this in the configuration of the datatable:

    $(document).ready(function() {
            var conta_col = document.getElementById("input_x").value;
            var table = $('#dataart').DataTable( {
              ....
              ....  
                "columns": [ 
                    {"width": "10%"},
                    {"width": "35%"},
                    {"width": "10%"},
                    {"width": "6%"},
                    {"width": "5%"},
                    while (conta_col >= 1) {
                        {"width": "5%"};
                        conta_col--;
                    },
                    {"width": "14%"}
                ],
...

Is it posible??? thank's.

1 Answer 1

3

The value you're giving as the value of the "columns" key in your data table is just an array.

var columns = 
     [ {"width": "10%"}
     , {"width": "35%"}
     , {"width": "10%"}
     , {"width": "6%"}
     , {"width": "5%"}
     ];
while (conta_col >= 1) {
    columns.push( { "width" : "5%" }; )
    conta_col--;
};
columns.push( {"width": "14%"} );
...
var table = ${'#dataart').DataTable( {
   ...
   "columns" : columns,
   ...
} );
...
Sign up to request clarification or add additional context in comments.

1 Comment

works fine, thank's. Only have to change columns.push( { "width" : "5%"} );. It's what I need. Thank you very much.

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.