Created row not transferred back to the table (compound key), thus datatable not refreshed correctly

Created row not transferred back to the table (compound key), thus datatable not refreshed correctly

marwal2marwal2 Posts: 6Questions: 3Answers: 0

Hello,

I am struggling a bit with refreshing datatable after new row is created through the form.
DB table has 3 primary keys, so I am using compound keys with additional where statements:

Editor::inst( $db, 'ppe', array('id', 'id_projektu', 'id_firmy'))
    ->fields(
        Field::inst( 'id' )->set( Field::SET_CREATE ),
        Field::inst( 'id_projektu' )->setValue($_SESSION['id_projektu']),
        Field::inst( 'id_firmy' )->setValue($_SESSION['id_firmy']), 

...

       })
    ->where( 'id_projektu', $_SESSION['id_projektu'] )
    ->where( 'id_firmy',    $_SESSION['id_firmy'] )
    ->debug(true)
    ->process( $_POST )
    ->json();

After user presses Create button the row data is saved correctly in DB.
However, that data is not transffered back to the datatable - new row is not displayed.
I have checked, if postCreate event is triggered in front-end, but it's not (because of no data most probably).
The response I get in the browser is as follows:

0: {name: ":where_0", value: "1", type: null}
1: {name: ":where_1", value: "1", type: null}
2: {name: ":where_2", value: "", type: null}
3: {name: ":where_3", value: "", type: null}
4: {name: ":where_4", value: "", type: null}
query: "SELECT  `id` as 'id', `id_projektu` as 'id_projektu', `id_firmy` as 'id_firmy', ... WHERE `id_projektu` = :where_0 AND  `id_firmy` = :where_1 AND  `id` = :where_2 AND  `id_projektu` = :where_3 AND  `id_firmy` = :where_4 "

I wonder why those 3 extra where commands are added to the query?
Why their values are set to empty strings?

I would like to add here that I want to display new row, without refreshing whole table - if possible ...

Thank you for answer.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Hi,

    Thanks for the question. Could you show me all of the raw JSON that the server responds with to the new row form submission please? I've got a feeling that the setValue isn't being used as part of the query for retrieval, but I'd like to check that.

    Thanks,
    Allan

  • marwal2marwal2 Posts: 6Questions: 3Answers: 0

    Hello Allan,

    This is JSON I am getting as a response after pressing Create button:

    {"data":[],"debug":[{"query":"SELECT  max(id) as 'max(id)' FROM  `ppe` WHERE `id_projektu` = :where_0 AND  `id_firmy` = :where_1 ","bindings":[{"name":":where_0","value":"2","type":null},{"name":":where_1","value":"1","type":null}]},{"query":"INSERT INTO  `ppe`  ( `id`, `id_projektu`, `id_firmy`, `zatwierdzam`, `progres`, `nazwa`, `osd`, `sprzedawca`, `kod`, `poczta`, `miejscowosc`, `ulica`, `nr_domu`, `nr_lokalu`, `rejon`, `faktura`, `umowa`, `termin_wyp_kompleksowej`, `termin_konca_kompleksowej`, `ppe_stary`, `ppe_nowy`, `licznik`, `taryfa`, `moc`, `prz`, `moc_pv`, `umowa_pv`, `s1`, `s2`, `s3`, `s4`, `status` ) VALUES (  :id,  :id_projektu,  :id_firmy,  :zatwierdzam,  :progres,  :nazwa,  :osd,  :sprzedawca,  :kod,  :poczta,  :miejscowosc,  :ulica,  :nr_domu,  :nr_lokalu,  :rejon,  :faktura,  :umowa,  :termin_wyp_kompleksowej,  :termin_konca_kompleksowej,  :ppe_stary,  :ppe_nowy,  :licznik,  :taryfa,  :moc,  :prz,  :moc_pv,  :umowa_pv,  :s1,  :s2,  :s3,  :s4,  :status )","bindings":[{"name":":id","value":"2","type":null},{"name":":id_projektu","value":"2","type":null},{"name":":id_firmy","value":"1","type":null},{"name":":zatwierdzam","value":0,"type":null},{"name":":progres","value":1,"type":null},{"name":":nazwa","value":"Fryzjer","type":null},{"name":":osd","value":"Tauron","type":null},{"name":":sprzedawca","value":"Tauron","type":null},{"name":":kod","value":"11-111","type":null},{"name":":poczta","value":"Ozimek","type":null},{"name":":miejscowosc","value":"Ozimek","type":null},{"name":":ulica","value":"S\u0142owackiego","type":null},{"name":":nr_domu","value":"1","type":null},{"name":":nr_lokalu","value":"1","type":null},{"name":":rejon","value":"A","type":null},{"name":":faktura","value":"Indywidualna","type":null},{"name":":umowa","value":"Rozdzielona","type":null},{"name":":termin_wyp_kompleksowej","value":null,"type":null},{"name":":termin_konca_kompleksowej","value":null,"type":null},{"name":":ppe_stary","value":"456","type":null},{"name":":ppe_nowy","value":"123","type":null},{"name":":licznik","value":"123456","type":null},{"name":":taryfa","value":"B11","type":null},{"name":":moc","value":"12","type":null},{"name":":prz","value":"","type":null},{"name":":moc_pv","value":"34","type":null},{"name":":umowa_pv","value":"Kupno \/ Odsprzeda\u017c","type":null},{"name":":s1","value":"1","type":null},{"name":":s2","value":"2","type":null},{"name":":s3","value":"3","type":null},{"name":":s4","value":"4","type":null},{"name":":status","value":"Aktywny","type":null}]},{"query":"SELECT  `id` as 'id', `id_projektu` as 'id_projektu', `id_firmy` as 'id_firmy', `zatwierdzam` as 'zatwierdzam', `progres` as 'progres', `nazwa` as 'nazwa', `osd` as 'osd', `sprzedawca` as 'sprzedawca', `kod` as 'kod', `poczta` as 'poczta', `miejscowosc` as 'miejscowosc', `ulica` as 'ulica', `nr_domu` as 'nr_domu', `nr_lokalu` as 'nr_lokalu', `rejon` as 'rejon', `faktura` as 'faktura', `umowa` as 'umowa', `termin_wyp_kompleksowej` as 'termin_wyp_kompleksowej', `termin_konca_kompleksowej` as 'termin_konca_kompleksowej', `ppe_stary` as 'ppe_stary', `ppe_nowy` as 'ppe_nowy', `licznik` as 'licznik', `taryfa` as 'taryfa', `moc` as 'moc', `prz` as 'prz', `moc_pv` as 'moc_pv', `umowa_pv` as 'umowa_pv', `s1` as 's1', `s2` as 's2', `s3` as 's3', `s4` as 's4', `status` as 'status' FROM  `ppe` WHERE `id_projektu` = :where_0 AND  `id_firmy` = :where_1 AND  `id` = :where_2 AND  `id_projektu` = :where_3 AND  `id_firmy` = :where_4 ","bindings":[{"name":":where_0","value":"2","type":null},{"name":":where_1","value":"1","type":null},{"name":":where_2","value":"","type":null},{"name":":where_3","value":"","type":null},{"name":":where_4","value":"","type":null}]}]}
    

    Thank you for your answer,
    Marek

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    HI Marek,

    Sorry for the delay in getting back to you here. I've not had a chance to dig into this properly yet, but will post back as soon as I can.

    Allan

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Hi Marek,

    The problem is here where $values are the values submitted from the client-side - which does not include the values set by setValue.

    I'll try to address this tomorrow - if not, I've got a workaround we could use in the short term using onCreate and modifying the array of values that was submitted.

    Regards,
    Allan

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    Here we go. If you copy that change into your local copy of the Editor.php file, that should do the job!

    Regards,
    Allan

  • marwal2marwal2 Posts: 6Questions: 3Answers: 0

    Hello Allan,

    Works fine! Thank you for a fix.

    Regards,
    Marek

This discussion has been closed.