Width of table doesn't change?

Width of table doesn't change?

SturmSturm Posts: 4Questions: 3Answers: 1

I've got a few DataTables that I'm working with and so far, I'm thrilled with this awesome and free plugin! I am, however, curious about one quirk of it that's kinda bugging me.

When the table is rendered, it appears that the plugin is placing a style="width: ####px" automatically on the <table> element. I never asked for this, and it seems to cause the table to not resize whenever the browser width is adjusted. I'm not asking about the Responsive extension; I'm not currently using it, although I may implement that in the future. For now, I just want to make sure the table stays at 100% of the width of its containing element.

Sure, I could put in a width: 100% !important; in my CSS on the selector .dataTable, but I was under the impression that using !important was considered bad form, so I'd rather avoid it if at all possible. So how can I prevent DataTables from auto-inserting that inline style?

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    In this example I removed width="100%" from the table:
    http://live.datatables.net/lulawura/1/edit

    When I inspect the table after Datatables initializes I see this:

    table.dataTable {
        width: 100%;
        margin: 0 auto;
        clear: both;
        border-collapse: separate;
        border-spacing: 0;
    }
    

    When you inspect your table can you see where the style="width: ####px" is coming from?

    Wonder if its related to a specific version.

    Kevin

This discussion has been closed.