How to set the table width in Jquery creating the datatable?

How to set the table width in Jquery creating the datatable?

laxmiparklaxmipark Posts: 22Questions: 8Answers: 0

$('#jquery_table').DataTable(

                    {
                        "autoWidth": false,
                        //lengthChange: false,
                        data: array,

                        "columns": [
                            { "data": "Assoc_ID", "title": "Manager ID"  },
                            { "data": "FullName", "title": "Full Name"},
                            {
                                "data": null, "targets": -1,

                                "defaultContent": "<button> View</button>",


                            }],
                        "columnDefs": [

                            {
                                "className": "dt-center", "targets": [1], "type": "string"
                            },
                            {
                                "className": "dt-center", "targets": [0], "type": "string"
                            },

                            { "width": "70px", "targets": 0 },
                            { "width": "100px", "targets": 1 },
                            { "width": "75px", "targets": 2 },
                        ],

                        //"caption": gd_title,
                        "scrollY": 300,
                        //"scrollX": true,
                        //"compact": true,
                        //"scroller": false,
                        "display": true,
                        "cell-border": true,
                        "paging": false,

                        dom: 'Bfrtip',
                        caption: [$.extend(true, HTMLLabelElement, {
                            text: "Direct Reports",
                            side: "top"
                        })
                        ],

I tried assigning the width to each column but that's not working.. where is it getting the width from.

Answers

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    Could be the content for the column larger than the size defined. Can you post a link or test case showing the issue?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @laxmipark ,

    As Kevin said, a test case base for these, as there's so many variables when it comes to setting the width. This example here may help though - it showing what you need to do (such as removing 100% from the HTML on the width, setting it in the CSS, etc.).

    Cheers,

    Colin

This discussion has been closed.