How change my php query using new parameters set by some checkBox options and redraw my DataTable?

How change my php query using new parameters set by some checkBox options and redraw my DataTable?

scbarrosscbarros Posts: 5Questions: 1Answers: 0

Hi, Masters!
I have some checkbox in my form and a (data)table.
If I click in one of them (checkboxes), I want to modify the parameters of search and send to server-side.
I'm trying to do a single call of a function to change a parameter sent to php, where it'll modify a query used to
retrieve a new block of data.
Using an object to persist the values does't work. Why when I change the value of Array, it doesn't affect the Datatable redraw?
Anyone would help me, please?

An example can be seeing in: http://spe-riscos.epizy.com/php/tabela_prod.php

My database is a very single MySQL table: id (int PK), dt_apres (varchar[255], id (varchar[255]), proposicao (varchar[1000]), ementa (varchar[1000]), detalhe (varchar[1000]), keywords (varchar[1000]), valor (varchar[100]), origem (char[1]).

Thanks in advance!

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    It would be worth look at Editor, as it makes modifying the table very straightforward.

    Colin

  • scbarrosscbarros Posts: 5Questions: 1Answers: 0

    Colin, thanks for your attention and opinion. Yes, I planning use Editor to do some alterations in database (include, modify or delete). But, in this case, I need to modify (in real time) the query that search informations in database through a checkboxes.
    ;o)

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Ah sorry, I misunderstood the question, I thought the checkboxes were in the table. You can amend what's sent to the server with ajax.data, which can then be read by the server-side scripts,

    Colin

  • scbarrosscbarros Posts: 5Questions: 1Answers: 0

    Colin, thanks again. Yes, I'm using an ajax.data option to send some parameters to the server-side (at the first time). However, when I change some checkbox (that mean some change in the query) doesn't work.
    In pratical terms:
    a) my first checkbox sets a parameter (like caseA = "A" or "[empty]");
    b) my second checkbox sets a parameter (like caseB = "X" or "[empty").
    After set this parameters, that will be stored in an Array, I'm using the ajax.data with this Array to send a new call to php file that get this parameters and add into a query (like this: SELECT a, b, c FROM table WHERE a = '100' AND case IN ('A', 'X', .....);)
    What happen? Nothing! Because I can't change the parameters sent in Array!
    In my (humble) knowledge, every time that I send a "requisition" to server-side, the parameters sent in ajax.data should be read.
    I'm using an Array because of the issue with visibility of variables.
    Best,
    San.

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,922
    Answer ✓

    The ajax.data examples show using a function which should send updated data. If you simply use an array then that value is basically hardcoded for ajax.data.

    Kevin

  • scbarrosscbarros Posts: 5Questions: 1Answers: 0

    Thanks Colin and Kevin! Yes, using a function fixed the issue:
    data: function (d) {
    return $.extend ( {}, d, {
    camara:$('#check_camara').prop('checked')
    });
    }

    ;o)

  • AndreOosthuizenAndreOosthuizen Posts: 14Questions: 3Answers: 0

    @scbarros, thanks for showing your solution. I think I have the same issue, can you please show your full java code as well as your php side, will appreciate.

    I have just posted a question a few minutes ago which I think is almost related to yours, I am not sure how to call the correct mysql select statement based on filter, search.

    https://datatables.net/forums/discussion/62513/determine-when-order-search-or-length-is-active-when-posting-server-side#latest

  • scbarrosscbarros Posts: 5Questions: 1Answers: 0

    Hi, Andre Oosthuizen!
    For sure!
    My code was posted (client & server-side) earlier. You can access the two files above. The only change was detached in my last post.
    Attention, please, that I had to change the ajax.data parameter, creating a function instead of send a single variable.
    Of course, if the issue persists, no not hesitate to explain better.
    Best regards,
    San.

This discussion has been closed.