Search code examples
javascriptjqueryjsonfootable

How to get array from json footable


I'm trying to get the data with json to generate a footable table with pagination but it's not working. my code actualy look like this. sorry my bad english.

my index.json is returning it

{
Cartas: [
{
id: 3,
user_id: 1,
status: "2",
banco_cartas: null,
nome: "teste",
contrato: "",
grupo: "430",
cota: "3332",
credito_atual: 154371.02,
prazo_original: "",
prazo_atual: "126",
valor_parcela: "0",
pc_pago: 1,
pc_fc: 0,
valor_pago: 154371.02,
saldo_devedor: null,
taxa: 0,
data_compra: "2003-03-28T00:00:00+00:00",
created: "2017-06-22T17:39:23-03:00",
data_contemplacao: "2016-12-20T00:00:00+00:00",
data_entrega: null
},
{
id: 4,
user_id: 1,
status: "2",
banco_cartas: null,
nome: "CAS REP comerciais",
contrato: "",
grupo: "240",
cota: "320",

my jquery to load the json in footable

jQuery(function($){
    $('#custom-ui-example').footable({
        "columns": [
                    { name: "nome",
                      title: "Nome"},
                      { name: "credito_atual",
                      title: "Crédito Atual"},
                      { name: "status",
                      title: "Status"}

                      ],
        "rows": $.get("index.json")
    })};

my html

<table class="table" id="custom-ui-example" data-paging="true"></table>

Solution

  • Index.json should return array of objects, in your case it is returning object.

    The format of the json should be

    [{'id': '3'},{'id': '4'}]
    

    Pagination seems to work fine.

    Find the working fiddle here: https://jsfiddle.net/qwwjs7j3/