Why not refresh data after ajax

Why not refresh data after ajax

pvidal_cuinerpvidal_cuiner Posts: 6Questions: 1Answers: 0

Data tables not run after load data from AJAX.

/* Data is additional to send with ajax petition */
var data = {tipo:'AgilPeticionLocalizador',id_empresa_sgw:$id_empresas,nombre_localizador:nombre_localizador}

$('#TablaLocalizador').dataTable({
    "processing": false,
    "serverSide": true,
    "pageLength": 10,
    "ajax": {
        "url": "{{ url('ProcesaAjaxLocalizador') }}",
        "dataType": 'json',
        "data": data
    }
});

And when show table data, it show all registers (100) and Nothing works: page, search, next page, etc.

What's my error?

This question has accepted answers - jump to:

Answers

  • pvidal_cuinerpvidal_cuiner Posts: 6Questions: 1Answers: 0

    Structured data:

    {
        "draw": 10,
        "data": [{
                "Codigo": "000000",
                "Descripcion": "USO INTERNO",
                "Familia": "Libre Texto Libre "
            }, {
                "Codigo": "100000",
                "Descripcion": "USO INTERNO INCIDENCIAS\u00a1\u00a1\u00a1",
                "Familia": "PRODUCTOS ALIMENTICIOS TEXTO LIBRE MAT.PRIMAS "
            }, {
                "Codigo": "101003",
                "Descripcion": "CAVIAR (Bote 550 Gr) 1234567890 1234567890 1234567890 1234567890 1234567890 123456789012345678901234",
                "Familia": "PRODUCTOS ALIMENTICIOS CONSERVAS "
            }, {
                "Codigo": "101004",
                "Descripcion": "CHAMPI\u00d1ON LAMINADO (Bote 2,5 Kg)",
                "Familia": "PRODUCTOS ALIMENTICIOS CONSERVAS "
            }, {
                "Codigo": "101005",
                "Descripcion": "PI\u00d1A DADOS (Bote 3,3 Kg)hnjghjghjghjjghjhgjghhjmghmjhmjhjm,hj,mjk,,kj,kj,",
                "Familia": "PRODUCTOS ALIMENTICIOS CONSERVAS "
            }, {
                "Codigo": "101006",
                "Descripcion": "MAIZ DULCE (Bote 300 Gr)",
                "Familia": "PRODUCTOS ALIMENTICIOS CONSERVAS "
            }, {
                "Codigo": "101009",
                "Descripcion": "GERMENES DE SOJA  (Bote 2,5 Kg)",
                "Familia": "PRODUCTOS ALIMENTICIOS CONSERVAS "
            }, 
                    .......
                    .......
                    [more to 100 registers]
        ],
        "recordsTotal": 912,
        "recordsFiltered": 100
    }
    
    

    Columns:

    [
        {"data": "Codigo"}, 
        {"data": "Descripcion"}, 
        {"data": "Familia"}
    ]
    
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Answer ✓

    Can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

    Also its not clear from the above, but if your returned data array is larger than 10, then the server-side script is doing the server-side processing wrong. It should only returned the records for the page.

    That said, you don't actually need server-side processing with only 1000 rows. Just remove serverSide: true.

    Allan

  • pvidal_cuinerpvidal_cuiner Posts: 6Questions: 1Answers: 0

    Ok, I have this paste code on Console Chrome. ¿What are " - click the upload button"?

  • pvidal_cuinerpvidal_cuiner Posts: 6Questions: 1Answers: 0

    OK. I Lookup the button. Have it.

  • pvidal_cuinerpvidal_cuiner Posts: 6Questions: 1Answers: 0

    What I need to do is:
    From Ajax make requests to the server on an Articles table that can have thousands of records.
    Initially I had thought to show the first 100, but then, when you paginate or search, go making requests of what was searched, ordered or paged.
    I have a remote REST system where I make the requests, I don't have the table in the local PHP code, so I'm interested in passing all the parameters that DATATABLES requests in serverside: true. (Search, Filter, Length, Start, etc.)

  • pvidal_cuinerpvidal_cuiner Posts: 6Questions: 1Answers: 0

    I've made it work, but it doesn't work the way I want it to.
    I've changed the order of the array data:

    {
        "draw": 0,
        "recordsTotal": 120,
        "recordsFiltered": 120,
        "data": [
            ["101003", "CAVIAR (Bote 550 Gr) 1234567890 1234567890 1234567890 1234567890 1234567890 123456789012345678901234", "PRODUCTOS ALIMENTICIOS CONSERVAS "], 
            ["101005", "PI\u00d1A DADOS (Bote 3,3 Kg)hnjghjghjghjjghjhgjghhjmghmjhmjhjm,hj,mjk,,kj,kj,", "PRODUCTOS ALIMENTICIOS CONSERVAS "], 
            ["101006", "MAIZ DULCE (Bote 300 Gr)", "PRODUCTOS ALIMENTICIOS CONSERVAS "], 
            ["101012", "PEPINILLO (Bote 345 Gr)", "PRODUCTOS ALIMENTICIOS CONSERVAS "], 
            ["101020", "CHAMPI\u00d1ON ENTERO (Bote 355 Ml)", "PRODUCTOS ALIMENTICIOS CONSERVAS "], 
            ["101022", "ALCACHOFA CUARTEADA (Bote 3 Kg)", "PRODUCTOS ALIMENTICIOS CONSERVAS "], 
            ["101029", "ALCAPARRAS (Bote 3 KG)", "PRODUCTOS ALIMENTICIOS CONSERVAS "], 
            ["101032", "CORAZONES ALCACHOFA (Bote 390 GR ) ", "PRODUCTOS ALIMENTICIOS CONSERVAS "], 
            ["102006", "PENNE RIGATE (Caja 3 Kg)", "PRODUCTOS ALIMENTICIOS PASTAS Y ARROZ "], 
            ["102013", "PLACA LASAGNA HUEVO (Caja 360 U)", "PRODUCTOS ALIMENTICIOS PASTAS Y ARROZ "]
        ]
    }
    
    

    If recordsTotal and recordsFiltered have after DATA not work.

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394
    Answer ✓

    Allan said:

    Can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

This discussion has been closed.