Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
JavaScript
<pre lang="xml"><script type="text/javascript">
        $(document).ready(function () {
            debugger;
            // Setup - add a text input to each footer cell
            $('#<%=example.ClientID%> tfoot th').each(function () {
                var title = $('#<%=example.ClientID%> thead th').eq($(this).index()).text();
                $(this).html('<input type="text" placeholder="Search ' + title + '" />');
            });

            // DataTable
            var table = $('#<%=example.ClientID%>').DataTable();

            // Apply the search
            table.columns().every(function () {
                var that = this;

                $('input', this.footer()).on('keyup change', function () {
                    that
                        .search(this.value)
                        .draw();
                });
            });
        });
    </script>




XML
<table cellspacing="0" rules="all" border="1" id="example" style="border-collapse: collapse;"  runat="server">
                <thead>
                    <tr>
                        <th scope="col">User Id
                        </th>
                        <th scope="col">UserName
                        </th>
                        <th scope="col">Education
                        </th>
                        <th scope="col">Location
                        </th>
                    </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th scope="col">User Id
                        </th>
                        <th scope="col">UserName
                        </th>
                        <th scope="col">Education
                        </th>
                        <th scope="col">Location
                        </th>
                    </tr>
                </tfoot>
                 <tbody>
                <tr>
                    <td>
                        <span>1</span>
                    </td>
                    <td>
                        <span>SureshDasari</span>
                    </td>
                    <td>
                        <span>B.Tech</span>
                    </td>
                    <td>
                        <span>Chennai</span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span>2</span>
                    </td>
                    <td>
                        <span>MadhavSai</span>
                    </td>
                    <td>
                        <span>MBA</span>
                    </td>
                    <td>
                        <span>Nagpur</span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span>3</span>
                    </td>
                    <td>
                        <span>MaheshDasari</span>
                    </td>
                    <td>
                        <span>B.Tech</span>
                    </td>
                    <td>
                        <span>Nuzividu</span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span>4</span>
                    </td>
                    <td>
                        <span>Rohini</span>
                    </td>
                    <td>
                        <span>MSC</span>
                    </td>
                    <td>
                        <span>Chennai</span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span>5</span>
                    </td>
                    <td>
                        <span>Mahendra</span>
                    </td>
                    <td>
                        <span>CA</span>
                    </td>
                    <td>
                        <span>Guntur</span>
                    </td>
                </tr>
                <tr>
                    <td>
                        <span>6</span>
                    </td>
                    <td>
                        <span>Honey</span>
                    </td>
                    <td>
                        <span>B.Tech</span>
                    </td>
                    <td>
                        <span>Nagpur</span>
                    </td>
                </tr>
                </tbody>
            </table>








Getting error in browser console "Uncaught TypeError: Cannot read property 'mData' of undefined"
Posted
Comments
Kornfeld Eliyahu Peter 20-Apr-15 5:53am    
Where?
Can you debug and see where exactly this issue is coming?
Arkadeep De 20-Apr-15 9:48am    
use class name instead of id...

1 solution

Hi Premalink,

plz trying doing with the following code changes. I am able to load the page without any console errors other than some imgs not found.

The only code change I made is replace "#<%=example.ClientID%" to "#example" check for the following code below.

XML
<script type="text/javascript">
        $(document).ready(function () {
            debugger;
            // Setup - add a text input to each footer cell
            $('#example tfoot th').each(function () {
                var title = $('thead th').eq($(this).index()).text();
                $(this).html('<input type="text" placeholder="Search ' + title + '" />');
            });

            // DataTable
            var table = $('#example').DataTable();

            // Apply the search
            table.columns().every(function () {
                var that = this;

                $('input', this.footer()).on('keyup change', function () {
                    that
                        .search(this.value)
                        .draw();
                });
            });
        });
</script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900