0

I have a jQuery datable pluged into my ASP.NET application and currently, in order to show the column names, I have the following piece of code in my Razor view..

<table id="myDataTable" class="display">
    <thead>
        <tr>
            <th>Contact name</th>
            <th>Title</th>
            <th>Country</th>
            <th>City</th>
            <th>Project</th>
        </tr>
    </thead>
    <tbody style="font-size:x-small"></tbody>
</table>

Then, I have my javascript for the jQuery datatbles...

$('#myDataTable').DataTable({
        "bServerSide": false,
        "sAjaxSource": //controller binding,
        "bAutoWidth": false,
        "bProcessing": true,
        "aoColumns": [
            { "sName": "CONTACT_NAME" },
            { "sName": "TITLE"},
            { "sName": "COUNTRY" },
            { "sName": "CITY" },
            { "sName": "PROJECT" },
        ],
        "bDestroy":true
    });

However, when I render the HTML the first time before I fill in the table, it looks awkward because I am rending some random HTML (that is related to the future column names) with no datatable at all...

How can I define the column of my table without having to set it in the HTML so I can avoid having that random text there?

Thanks!

2
  • Are you talking about a flash of unstyled content? Try starting with the html part hidden. Commented Dec 17, 2015 at 20:08
  • Hi, no flash in here. Basically I just have a HTML that will render the column names once I enhance with the jQuery datatables but before I enhance with the datatables I want it to be hidden. If I try to use the HTML hidden attribute, then it will be always hidden as I don't know a way to distinguish when I've called the datatables. Not sure if my explanation makes sense though :) Commented Dec 17, 2015 at 20:20

1 Answer 1

1

just set the initial CSS of the #myDataTable to visibility:hidden; like this:

#myDataTable { visibility:hidden; }

That way you can put it right in the HTML and just call the following JavaScript to show it after you update the values:

document.getElementById('#myDataTable').style.visibility = "visible";
Sign up to request clarification or add additional context in comments.

2 Comments

Nice! It did the trick! However, I had to set it like this... document.getElementById('myDataTable').style.visibility = "visible";
arf ... right... hashtag on the brain, sorry ;) (glad it worked out for you)

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.