Is there a way to Export All while using server side processing? - Page 2

Is there a way to Export All while using server side processing?

2»

Answers

  • mmcnair80mmcnair80 Posts: 83Questions: 21Answers: 7

    I have figured out how to do this for my setup.

    My button initialization:

        $.fn.dataTable.ext.buttons.export =
        {
            className: 'buttons-alert',
            id: 'ExportButton',
            text: "Export All To Excel",
            action: function (e, dt, node, config)
            {
                window.location.href = './ServerSide.php?ExportToExcel=Yes';
            }
        };
    

    This sends my browser to my ServerSide.php file which looks for the Yes and does this:

    if (isset($_GET['ExportToExcel']) && $_GET['ExportToExcel'] == 'Yes')
    {
        $GetSQL = "Select Value from PostKept";
        $KeepResult = $conn->query($GetSQL);
        $KeepResults = $KeepResult->fetchALL(PDO::FETCH_ASSOC);
        $request = unserialize($KeepResults[0]['Value']);
        
        $DataReturn = json_encode(FilterSort::complex($request,$sqlConnect,$table,$primaryKey,$ColumnHeader,1));
        require './ExportAllToExcel.php';
    }
    

    That's a little bit different from above, but it's the only part that I changed. Then because the data that I'm trying to save from what the user is filtering and sorting was exceeding the size limit on the cookie that I was setting (which meant that it wasn't getting set) I added and included file KeepPost.php that does this:

    if( isset($_POST['draw']))
    {
        include 'DBConn.php';
        $KeepPost = $_POST;    
        $KeepPost['length'] = -1;
        $PostKept = serialize($KeepPost);
        $TSQL = "UPDATE PostKept set Value = '" .$PostKept. "'";
        $sth = $conn->prepare($TSQL);
        $sth->execute();
    }
    

    Now since the sorting and filtering data are kept I'm able to use that to get the data that is needed when the ServerSide.php calls the FilterSort.class.php and send that data to the ExportAllToExcel.php which then creates an Excel file and sends it to the client.

This discussion has been closed.