wenzhixin / bootstrap-table

An extended table to integration with some of the most widely used CSS frameworks. (Supports Bootstrap, Semantic UI, Bulma, Material Design, Foundation, Vue.js)
https://bootstrap-table.com/
MIT License
11.74k stars 4.44k forks source link

Unable to export all table data with php server side pagination #4367

Closed somunath closed 5 years ago

somunath commented 5 years ago

I have using bootstrap-table.js version 1.11.1. Everything is working fine except the export parts. It only exports the visible rows in the page but it doesn't exports "all" and "selected" as well.

Below is my php server side code:

<?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "dbname";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);

    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }else{
        $a_json = array();
        $temp = array();
        $a_json_row = array();

        if (isset($_GET['search'])) {
            $WHERE = ' WHERE first_name LIKE "%'.$_GET['search'].'%" ';
        } else {
            $WHERE = NULL;
        }

        $sql = "SELECT labour_id, first_name, last_name FROM labour_details ".$WHERE." ORDER BY labour_id LIMIT ".$_GET['offset'].",".$_GET['limit']."";
        $result = $conn->query($sql);
        if ($result->num_rows > 0) {
            while($row = $result->fetch_assoc()) {
                $a_json_row["Labour_Id"] = $row["labour_id"];
                $a_json_row["First_Name"] = $row["first_name"];
                $a_json_row["Last_Name"] = $row["last_name"];
                array_push($temp, $a_json_row);
            }
        } else {
            echo "0 results";
        }

        $sql2 = "SELECT count(*) as total FROM labour_details ".$WHERE."";
        $result2 = $conn->query($sql2);
        $data = $result2->fetch_assoc();
        $conn->close();

        echo json_encode(array(
            'total' => $data['total'], // total numbers
            'rows' => $temp
        ));
    }

And here is the html table part:

<table id="table" data-toggle="table" data-url="getdata.php" data-side-pagination="server" data-pagination="true" data-search="true" data-show-columns="true" data-show-pagination-switch="true" data-show-refresh="true" data-key-events="true" data-show-toggle="true" data-resizable="true" data-cookie="true" data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar">
                 <thead>
                 <tr>
                  <th data-field="state" data-checkbox="true"></th>
                  <th data-field="Labour_Id">Labour ID</th>
                   <th data-field="First_Name" data-editable="true">First Name</th>
                   <th data-field="Last_Name" data-editable="true">Last Name</th>

                  </tr>
                  </thead>
</table>

And in the bootstrap-table.js file i have set the line 311 to server as

sidePagination: 'server', // client or server

Please, help me solve the problem. I just need the export part to work well as per my need.

UtechtDustin commented 5 years ago

First of all... this is the wrong repository for your question, the right repository is this one: https://github.com/wenzhixin/bootstrap-table @wenzhixin Please move it.

Also please format your using Markdown (Code block).

The next step is to use the newest version of the bootstrap table, you are using 1.11. but the newest version is the 1.14.2! So please update an test it again.

somunath commented 5 years ago

OK, sorry about that, first time in GitHub. Now i have updated the with proper formating

wenzhixin commented 5 years ago

Transferred this issue, @somunath please test it in the latest version. In our example: https://examples.bootstrap-table.com/#extensions/export.html, it works well.

I think in your example, you need to handle $_GET['offset'] and $_GET['limit'] because when using all export type, the request params don't contain the offset and limit, and return all records.

somunath commented 5 years ago

Could You Please tell me which are the js and css files i need to update

wenzhixin commented 5 years ago

https://examples.bootstrap-table.com/#welcome.html#view-source

UtechtDustin commented 5 years ago

All js and css files your currently using from the bootstrap-table :-)

somunath commented 5 years ago

OK.. thanks. Let me try first. will respond back. And Thank you both so much for your help.

wenzhixin commented 5 years ago

You need to return all data without offset and limit params, for example, https://examples.wenzhixin.net.cn/examples/bootstrap_table/data.

somunath commented 5 years ago

Under such case my above php code isn't going to work right?

somunath commented 5 years ago

The data-url always sends offset and limit to the server script. How do i prevent it from sending offset and limit in case export event is clicked or is there a way to send addition parameter when export is clicked.

somunath commented 5 years ago

Could you plz tell me how to send an additional parameter to data-url if export is invoked?

UtechtDustin commented 5 years ago

I guess you can use the queryParams option.

Btw. we have a documentation (the link above can be found easily by searching in the documentation).

somunath commented 5 years ago

Could you please provide me a sample code on how to send an additional parameter when and only when the excel or csv export is invoked

UtechtDustin commented 5 years ago

There is a sample code on the documentation, just click on the </> on the example page. I don think its currently possible to send it only if th export event is invoked. But there should no problem to send it on every event, just ignore it on the server side.

somunath commented 5 years ago

Hello, I want to try this example given here https://examples.bootstrap-table.com/#issues/3830.html#view-source. I can't get it to work. Please tell me what are the additional js and css files in need.

as of now i have tried as bellow: `<!doctype html>

Dashboard v.1.0 | Adminpro - Admin Template
ID Item Name Item Price
`
UtechtDustin commented 5 years ago

You can see the required js/css files in the example. If you need help please provide us an example(jsfiddle!) of your not working test instead or pasting your code without any formatting.

somunath commented 5 years ago

Thanks guys for your help. By the way i have solved the problem. Now its working fine. I have integrated it in laravel. Thank you again.

UtechtDustin commented 5 years ago

Your welcome!

somunath commented 5 years ago

The bootstrap-table library is awesome. The author's work is highly appreciated