4

I'm looking for help jquery data-tables header and columns width size mismatching. i mean columns size is varying based on the text lenght(datatable values).How to fix the columns should be standard width and match with tale header.

Another issue is pagination.I'm looking pagination style like Example of pagination , but i'm not getting same style in my table.Please help me.

And another request for apply same theme which given example (theme redmond) to datatable.

Please find the below my datatable in jsfiddle JSFIDDLE

$("#products1").dataTable({
       "aaData": newarray,
       "bProcessing": true,
       "bDeferRender": true,
       "bFilter": false,
       "bJQueryUI": true,
       "sPaginationType": "full_numbers",
       "bRetrieve": true,
       "bPaginate": true,
       "bSort": true,
       "aaSorting": [[4, "desc"]],
       "iDisplayLength": 5,
       "oLanguage":{
                "sInfo":"_START_-_END_ of _TOTAL_",
                "oPaginate":{
                    "sFirst": "<<",
                    "sLast": ">>",
                    "sNext": ">",
                    "sPrevious": "<" 
                },
                "sLengthMenu":"Show _MENU_"
            },
       "aoColumns": [{"sWidth": "100%","sClass": "center","bSortable": false},
             {
            "sWidth": "150%","sClass": "center","bSortable": false},
             {
            "sWidth": "150%","sClass": "center","bSortable": false},
             {
            "sWidth": "150%","sClass": "center","bSortable": false}


            ],
        "aoColumnDefs": [{ "fnRender": function (o, val) {
            return o.aData[0];
        },
            "sClass": "HEADER","aTargets": [0]
    }, {
        "fnRender": function (o, val) {

            return o.aData[1];
        },
            "sClass": "list","aTargets": [1]
    }, {
    "fnRender": function (o, val) {

            return o.aData[2];
        },
            "sClass": " Number","aTargets": [2]
    },{
    "fnRender": function (o, val) {

            return o.aData[3];
        },
            "sClass": "Name","aTargets": [3]
    }]

});

4 Answers 4

4

You need to put this in table for fixed size column

EDIT: You missed to write table width and layout in style of table, I hope following will work for you

<table border="1" cellspacing="0" cellpadding="0" id="products" style="clear:both;layout:fixed;width:400px;">
    <col style="width: 40%"/>
        <col style="width: 30%"/>
        <col style="width: 10%"/>
        <col style="width:20%"/>

Check update updated fiddle

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

Comments

2

It was just a minor typo by codeomnitrix, but the answer is correct. Instead of layout, it should be table-layout:

style="clear:both;table-layout:fixed;width:400px;"

This will overwrite the bootstrap CSS setting that causes the mismatch of header and body columns.

Comments

2

this statement used in any context will match the header up with the columns. I would suggest binding it inside a function that is bound to the UI change.

$($.fn.dataTable.tables(true)).DataTable().columns.adjust();

https://www.gyrocode.com/articles/jquery-datatables-column-width-issues-with-bootstrap-tabs/

Comments

1

$('table.dataTable').wrap('<div class="datatableWrapperdiv"></div>')

with following css

.datatableWrapperdiv{ overflow-x:auto; width:100%; }

Comments

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.