Monday 5 November 2012

Java Script code that sorts table data / Sort Table Data using JavaScript / Table sorting on Client Side


Sort Table Data using JavaScript / Table sorting on Client Side


Hi Friends ,
Here by I have mentioned code to sort table using java script with out post back.

Steps 1 : 

Create a java script file File  named by “jstoSortTable.js” and past following code.

 Download JS

Step 2:

Create a html file or aspx file and add reference of Js file into header .

<head runat="server">

    <script src=" jstoSortTable.js"></script>

</head>

Step 3:


call initTable method on body onload : <body onload='initTable("mytable");'>  “Mytable” is the id of your table which you want to sort.

  

Full CODE :

<body onload='initTable("mytable");'>
    <form id="form1" runat="server">
        <table id="mytable" border="1" style="width:40%;font-family:Verdana;">
            <tbody>
                <tr>
                    <th>
                        ID</th>
                    <th>
                        Name</th>
                    <th>
                        City</th>
                </tr>
                <tr>
                    <td>
                        1</td>
                    <td>
                        Jeet</td>
                    <td>
                        USA</td>
                </tr>
                <tr>
                    <td>
                        2</td>
                    <td>
                        Tarun</td>
                    <td>
                        Jaipur</td>
                </tr>
                <tr>
                    <td>
                        3</td>
                    <td>
                        Jai</td>
                    <td>
                        USA</td>
                </tr>
                <tr>
                    <td>
                        4</td>
                    <td>
                        Amit</td>
                    <td>
                        Jaipur</td>
                </tr>
        </table>
    </form>
</body>


:) Enjoy Program


1 comment: