Click here to Skip to main content
14,868,570 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i am trying to add export excel button to my table here is my code:
<script src="vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" >
    $(function () {
        $.ajax({
            type: "POST",
            url: "daily.aspx/GetCustomers",
            data: '{}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: OnSuccess,
            failure: function (response) {
                alert(response.d);
            },
            error: function (response) {
                alert(response.d);
            }
        });
    });
    function OnSuccess(response) {
        $("[id*=GridView2]").DataTable(
            {
                "sScrollX": "100%",
                "bScrollCollapse": true,
                scrollY: "100%",
                bLengthChange: true,
                lengthMenu: [[5, 10,20, -1], [5, 10,20, "All"]],
                bFilter: true,
                bSort: true,
                bPaginate: true,
                data: response.d,
                columns: [{ 'data': 'sitecode' },
                    { 'data': 'siteid' },
                    { 'data': 'region' }]
            });
    };
</script>


What I have tried:

i tried to add
buttons: [
           'copyHtml5',
           'excelHtml5',
           'csvHtml5',
           'pdfHtml5'
       ]

in side the function
function OnSuccess(response) {
        $("[id*=GridView2]").DataTable(
            {

but it doesnt work
Posted
Comments
Gerry Schmitz 7-Mar-21 14:32pm
   
Get the user to "import" (html tables) using their Excel. It does a better job than you could ever hope to.

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