Print Html Table in Asp.net Jquery

<html>
<head>
<script src="Jquery.1.10.2.js" type="text/javascript"></script>
<script type="text/javascript">



    function btnPrint_onclick() {
        $('#tblcat td:nth-child(2), th:nth-child(2)').remove();
        $('#tblcat_length').hide();
        $('#tblcat_filter').hide();
        $('#tblcat_info').hide();
        $('#tblcat_first').hide();
        $('#tblcat_previous').hide();
        $('#tblcat_next').hide();
        $('#tblcat_last').hide();

        var docprint = window.open("about:blank", "_blank");
        var oTable = document.getElementById("tblcat");
        docprint.document.open();
        docprint.document.write('<html><head><title>Master</title>');
        docprint.document.write('</head><body><center>');
        docprint.document.write(oTable.parentNode.innerHTML);
        docprint.document.write('</center></body></html>');
        docprint.document.close();

        docprint.print();
        docprint.close();

        $('#tblcat_length').show();
        $('#tblcat_filter').show();
        $('#tblcat_info').show();

        window.location.reload();
        return false;
    }

    </script>

</head>
<body>
<input type="button" id="btnPrint" class="btn btn-primary" value="Print"  onclick="return btnPrint_onclick()" />

<table id="tblcat" class="display" cellspacing="0" width="100%" border="1" >
                            <thead>
                                <tr style="background-color:#5C677E;color:#FFFFFF;">
                                    <th style="width: 10%;">
                                        S. No.
                                    </th>
                                    <th style="width: 10%; display: none;">
                                        ID
                                    </th>
                                    <th style="width: 25%;">
                                        Code
                                    </th>
                                    <th style="width: 40%;">
                                    Country
                                    </th>
                              
                                </tr>
                            </thead>
    <tr style="background-color:#5C677E;color:#FFFFFF;">
                                    <td style="width: 10%;">
                                        1
                                    </td>
                                    <td style="width: 10%; display: none;">
                                        001
                                    </td>
                                    <td style="width: 25%;">
                                        IND
                                    </td>
                                    <td style="width: 40%;">
                                        India
                                    </td>
                             
                                </tr>
                                <tr style="background-color:#5C677E;color:#FFFFFF;">
                                    <td style="width: 10%;">
                                        2
                                    </td>
                                    <td style="width: 10%; display: none;">
                                        002
                                    </td>
                                    <td style="width: 25%;">
                                        AUS
                                    </td>
                                    <td style="width: 40%;">
                                        Australia
                                    </td>
                              
                                </tr>
                        </table>

</body>
</html>

Comments

Popular posts from this blog

Unable to perform operation on the item is locked in workspace

Maximum Stored Procedure Function Trigger or View Nesting Level Exceeded (limit 32) in SQL Server

Insecure cookie setting: missing Secure flag