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

cannot load json data #610

Closed BenJule closed 9 years ago

BenJule commented 9 years ago

Hi togeher,

My Files

nodes.json: http://paste.debian.net/hidden/85d8c632/ getData.html: http://paste.debian.net/hidden/b9df2a32/ welcome.html http://paste.debian.net/hidden/10c94b9b/

Problem

No matching records found!

Anyone ideas?

djhvscf commented 9 years ago

Ok, let me check! @BenJule

BenJule commented 9 years ago

Thanks for helping. The file "nodes.json" is automatically generated. I can not change the structure.

djhvscf commented 9 years ago

I think the problem is that your ,json file is not a flat json.. you can use this extension to do that https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/flatJSON and here is the example: http://issues.wenzhixin.net.cn/bootstrap-table/#extensions/flatJSON.html

@BenJule

BenJule commented 9 years ago

TypeError: $.fn.bootstrapTable is undefined My nodes.html: http://paste.debian.net/hidden/f73cc344/ My nodes.json: http://paste.debian.net/hidden/a38bdf4f/ The Problem is, the structure of json file, example.json is working fine but with my json file, it gives trouble!

@djhvscf

djhvscf commented 9 years ago

Ok, let me check again! @BenJule

BenJule commented 9 years ago

@djhvscf i have find the trouble. Please check my nodes.json:

  1. line "nodes": [

Were can i change the option from "rows": [ to "nodes": [ ?

djhvscf commented 9 years ago

I think the flatJSON extension works for you. @BenJule

BenJule commented 9 years ago

not realy. i need to change the read option from "rows": [ to "nodes": [ but i dount know, were can i find it :/ http://paste.debian.net/hidden/4cbb16f8/ is (working) http://paste.debian.net/hidden/bf080cf1/ is (not working) @djhvscf

djhvscf commented 9 years ago

Do you mean change the word "rows" to "nodes" and no change the struture of the json? @BenJule

BenJule commented 9 years ago

:+1:

djhvscf commented 9 years ago

Am I correct?

BenJule commented 9 years ago

yes

djhvscf commented 9 years ago

ok, got it.. let me think what we can do with this problem

BenJule commented 9 years ago

the funktion "rows" is not hardcoded?

djhvscf commented 9 years ago

Now I'm understanding the problem is related to this line..

data = data.rows;

BenJule commented 9 years ago

in file?

djhvscf commented 9 years ago

As far I can understand I think is related to this function:

BootstrapTable.prototype.load = function (data) {
        var fixedScroll = false;

        // #431: support pagination
        if (this.options.sidePagination === 'server') {
            this.options.totalRows = data.total;
            fixedScroll = data.fixedScroll;
            data = data.rows;
        } else if (!$.isArray(data)) { // support fixedScroll
            fixedScroll = data.fixedScroll;
            data = data.data;
        }

        this.initData(data);
        this.initSearch();
        this.initPagination();
        this.initBody(fixedScroll);
    };
BenJule commented 9 years ago

ahhh thanks @djhvscf , i have found the solution.

djhvscf commented 9 years ago

Can you tell us what is your solution? @BenJule

BenJule commented 9 years ago

I was change the line data = data.rows; -> data = data.nodes;

BootstrapTable.prototype.load = function (data) {
        var fixedScroll = false;

        // #431: support pagination
        if (this.options.sidePagination === 'server') {
            this.options.totalRows = data.total;
            fixedScroll = data.fixedScroll;
            data = data.rows; // <-- related this function
        } else if (!$.isArray(data)) { // support fixedScroll
            fixedScroll = data.fixedScroll;
            data = data.data;
        }

        this.initData(data);
        this.initSearch();
        this.initPagination();
        this.initBody(fixedScroll);
    };
djhvscf commented 9 years ago

Ok, I think we have to review that method because is not a common solution for all us! Thank you!

wenzhixin commented 9 years ago

There is an option: responseHandler, and it can easy to resolve your problem:

responseHandler: function (res) {
    return res.nodes;
}

PS: it is not recommended to modify the source code. Here is the Docs. The example: http://issues.wenzhixin.net.cn/bootstrap-table/#353.html. The json: https://github.com/wenzhixin/bootstrap-table-examples/blob/master/json/353.json.

BenJule commented 9 years ago

Hi @djhvscf & @wenzhixin

The option responseHandler isnt working!

responseHandler: function (res) {
    return res.nodes;
}

Please check my Site: http://benjule.github.io/project-categories/bootstrap-table-test/ and my github.io: https://github.com/BenJule/benjule.github.io

djhvscf commented 9 years ago

What exactly do we have to see??

wenzhixin commented 9 years ago

I have the same problem.

BenJule commented 9 years ago

@djhvscf please see, http://benjule.github.io/project-categories/bootstrap-table-test/

there is no output with tables!

djhvscf commented 9 years ago

First error.. No including the jQuery reference..

Review this, please.

nojquery

BenJule commented 9 years ago

omg, thanks @djhvscf

BenJule commented 9 years ago

@wenzhixin @djhvscf my json format was changed :-1: New Format: https://gist.github.com/BenJule/06c23346bc6995f82333. Its possible to read this format?

djhvscf commented 9 years ago

Of course.. you can use the flatJSON extension to read the JSON.. See this: http://issues.wenzhixin.net.cn/bootstrap-table/#extensions/flatJSON.html and this: https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/flatJSON

BenJule commented 9 years ago

@djhvscf there isnt working, see http://gw3.ff3l.fr/?page=test the jsonfile is differen as example data3.json

djhvscf commented 9 years ago

What about your table config?

BenJule commented 9 years ago

No matching records found!

BenJule commented 9 years ago
        <table id="table"
               data-toggle="table"
               data-flat="true"
               data-search="true"
               data-url="./db/ff3l.json">
            <thead>
            <tr>
                <th data-field="hostname" data-sortable="true">Hostname</th>
                <th data-field="uptime" data-sortable="true">Uptime</th>
                <th data-field="tx" data-sortable="true">TX(MB)</th>
                <th data-field="rx" data-sortable="true">RX(MB)</th>
                <th data-field="firmware" data-sortable="true">Firmware</th>
                <th data-field="model" data-sortable="true">Model</th>
                <th data-field="autoupdate" data-sortable="true">Autoupdate</th>
                <th data-field="loadavg" data-sortable="true">Load AVG</th>
                <th data-field="memfree" data-sortable="true">Mem Free</th>
            </tr>
            </thead>
        </table>
djhvscf commented 9 years ago

Let me check it