1

I am trying to implement datatables.net on my asp.net gridview. I have included the necessary js and css files.

I am applying the datatables using

$(document).ready(function(){
    $('#myGridview').dataTable();
});

but it is not working. It is showing the exception in console :

"Cannot read property 'mData' of undefined"

can anyone help me out with this ?

Thanks

7
  • What version of jQuery are you including? Commented May 24, 2014 at 7:52
  • //code.jquery.com/jquery-1.10.2.min.js as suggested on the datatables site Commented May 24, 2014 at 7:54
  • Then it sounds like your table doesn't have a thead or tbody tag Commented May 24, 2014 at 7:56
  • yes i read that while googling this issue. but asp.net gridview is creating the table structure itself. So how can i deal with that. Please share your views if you have implemented it on gridview. Commented May 24, 2014 at 7:57
  • datatables requires the table to have a thead and tbody section -- I'm not familiar with C# or asp.net though, so I'm not sure how to make that happen Commented May 24, 2014 at 7:59

1 Answer 1

6

Here is the work around to this problem.

This error shows up because datatables.js requires thead and tbody attributes. Now asp.net gridview does not generate the attribute itself when it is rendered as html which caused datatables.js to fail.

So in order to generate in gridview please add following code in page load which will create the attributes for gridview.

 GridView1.UseAccessibleHeader = true;

//adds <thead> and <tbody> elements

GridView1.HeaderRow.TableSection =  TableRowSection.TableHeader;

and you are good to go with datatables.js

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

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.