API de pesquisa de coluna com server side processing.

API de pesquisa de coluna com server side processing.

DumbleDWDumbleDW Posts: 15Questions: 2Answers: 0

Alguém poderia me mostrar um exemplo do uso da API de pesquisa de coluna junto com processamento do lado do servidor?

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 20,247Questions: 26Answers: 4,760

    The Server Side Processing docs explain the protocol used. In the docs it shows the column search information is passed as part of the parameters. Your server script is responsible looking at the parameters to setup the DB query for each column search.

    The ssp.class.php file used in the Server Side examples can be found here. This will give you the basics of what needs to be in your server script.

    Kevin

  • DumbleDWDumbleDW Posts: 15Questions: 2Answers: 0

    Me tira uma duvida, tem que ser alterado alguma coisa no ssp.class? porque simplesmente não funciona em meu código, ele fica como processing... infinito.

  • kthorngrenkthorngren Posts: 20,247Questions: 26Answers: 4,760

    Check the browser's console for errors.

    Kevin

  • DumbleDWDumbleDW Posts: 15Questions: 2Answers: 0
    edited January 2022


    Não relata nenhum erro, ao olhar o console na parte de rede ele ainda mostra os resultados
    .

  • kthorngrenkthorngren Posts: 20,247Questions: 26Answers: 4,760

    The problem is your server script is returning draw: 0. The server side docs provide the details of this parameter. It is a sequence number that the client uses to make sure its processing the correct response. When Datatables initializes it sends draw: 1, look at the request tab, and expects draw: 1 in the response. The response should never have 0.

    Kevin

  • DumbleDWDumbleDW Posts: 15Questions: 2Answers: 0
    edited January 2022

    Ao mudar o tipo _GET para _POST o draw foi alterado para 1 porém a tabela me retornou vazia:

    Segue os links dos códigos:
    https://sourceb.in/5JhOm30qpm
    https://sourceb.in/6zKSDDkt9U

  • kthorngrenkthorngren Posts: 20,247Questions: 26Answers: 4,760

    Please post your Datatables initialization code.

    Kevin

  • kthorngrenkthorngren Posts: 20,247Questions: 26Answers: 4,760
    Answer ✓

    You have this:

                        'columns': [
                            { data: 'data_criacao',"defaultContent": ""},
                            { data: 'status_equipamento',"defaultContent": "" },
                            { data: 'localidade',"defaultContent": "" },
                            { data: 'ativo',"defaultContent": "" },
                            { data: 'numero_serie',"defaultContent": "" },
                            { data: 'nome_colaborador',"defaultContent": "" },
                            { data: 'departamento',"defaultContent": "" },
                            { data: 'id',"defaultContent": "", render: function (data){return '<a class="btn btn-primary" href="altera-form-produto.php?id='+data+'"><svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" class="bi bi-pencil" viewBox="0 0 16 16"><path d="M12.146.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1 0 .708l-10 10a.5.5 0 0 1-.168.11l-5 2a.5.5 0 0 1-.65-.65l2-5a.5.5 0 0 1 .11-.168l10-10zM11.207 2.5 13.5 4.793 14.793 3.5 12.5 1.207 11.207 2.5zm1.586 3L10.5 3.207 4 9.707V10h.5a.5.5 0 0 1 .5.5v.5h.5a.5.5 0 0 1 .5.5v.5h.293l6.5-6.5zm-9.761 5.175-.106.106-1.528 3.821 3.821-1.528.106-.106A.5.5 0 0 1 5 12.5V12h-.5a.5.5 0 0 1-.5-.5V11h-.5a.5.5 0 0 1-.468-.325z"/></svg></a>  <a class="btn btn-danger" href="delete_lista_rat.php?id='+data+'"><svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" fill="currentColor" class="bi bi-person-x" viewBox="0 0 16 16"><path d="M6 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6zm2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0zm4 8c0 1-1 1-1 1H1s-1 0-1-1 1-4 6-4 6 3 6 4zm-1-.004c-.001-.246-.154-.986-.832-1.664C9.516 10.68 8.289 10 6 10c-2.29 0-3.516.68-4.168 1.332-.678.678-.83 1.418-.832 1.664h10z"/><path fill-rule="evenodd" d="M12.146 5.146a.5.5 0 0 1 .708 0L14 6.293l1.146-1.147a.5.5 0 0 1 .708.708L14.707 7l1.147 1.146a.5.5 0 0 1-.708.708L14 7.707l-1.146 1.147a.5.5 0 0 1-.708-.708L13.293 7l-1.147-1.146a.5.5 0 0 1 0-.708z"/></svg></a>'}
                            }],
    

    Your row data are in arrays but you have defined columns.data which is telling Datatables that your row data is objects. Since the objects aren't there its using the defaultContent setting to display empty data. See the data docs for more details.

    Its better to use objects. My suggestion is to change your server script to return object structured rows. See this example.

    Kevin

  • DumbleDWDumbleDW Posts: 15Questions: 2Answers: 0

    Muito obrigado Kevin, retornando estruturas de objeto funcionou perfeitamente, sabe me dizer se tem como adaptar com essa função?
    https://datatables.net/examples/api/multi_filter_select.html

  • kthorngrenkthorngren Posts: 20,247Questions: 26Answers: 4,760
    Answer ✓

    See if this thread helps.

    Kevin

Sign In or Register to comment.