RETURN DEF - Page 3

RETURN DEF

13»

Replies

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Good. I managed to get several questions right.

    First:
    In columns, for me to be able to sort by clicking

    {
        title: "DT.NASCIMENTO",
        data: 'clipacdatnas',
        "type": "date-eu" ///// note that the js https://cdn.datatables.net/plug-ins/1.10.12/sorting/date-eu.js is used
    }
    

    Second:
    In the editor, the clipacdatnas field

    {
        label: "DATE ​​OF BIRTH:",
        name: "clipacdatnas",
        type: 'date',
        def: function () {return new Date (); },
        dateFormat: 'dd / mm / yy',
    }
    

    Third:
    In the php I generate the data for the datatable, before the json_encode, I use the code below, because you instructed me to generate the json
    with the date already in DD / MM / YYYY format. However, if in the table in the database, this clipacdatnas column is NULL, it generates a date 12/31/1969.

    if ($ row_data ["clipacdatnas"]! == NULL) {
        $ data ['clipacdatnas'] = date ('d / m / Y', strtotime ($ row_data ["clipacdatnas"]));
        } else {
        $ data ['clipacdatnas'] = '';
    }
    

    Fourth:
    In the php of the editor that submits the data, I use:

    Field :: inst ('clipacdatnas') -> setFormatter (Format :: dateFormatToSql ("d / m / Y")), ////// Here it does it correctly, it writes correctly to the database

    When I run create, and insert a date 20/06/2020 it writes correctly in the database = 2020-06-20
    When I run the edit, and insert a date 20/06/2020 it writes correctly in the database = 2020-06-20

    Now the problem:
    When I submit the editor, either by create or edit, and reopen the editor again, those dates that I recorded correctly in the database
    is shown to be totally wrong, for example, 06/12/2025. I need to refresh the page by running the page refresh so that I can open the
    editor again and show the correct date 20/06/2020.

    I think I was totally specific in the explanation.

    So my question. Is the way I'm doing it a good way? Is there another way that is simpler, with less code for this to work?
    Do I need to use parallel js to work a simple order when clicking on a column?
    Anyway, I'm finding it a bit complex, having to go around a lot, "sewing" codes so that a simple function works.
    Thus, I will not be able to present the tool to the company and thus acquire it.
    If you can help me with this and present me with a clear and objective solution to these questions above, I would appreciate it, because I am 3 days in it,
    for something so simple, but that the tool seems to hinder.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    However, if in the table in the database, this clipacdatnas column is NULL, it generates a date 12/31/1969.

    That is what PHP's strtotime function will do if you pass in null (since it converts to the unix epoch which starts at 1st Jan 1970). You would need a condition to check if the value is null and if so, just return an empty string or null itself. This is what our PHP libraries do but you don't appear to be using them?

    Is the way I'm doing it a good way? Is there another way that is simpler, with less code for this to work?

    I still think we should debug why datetime is not working. The whole thing will be much easier using that than jQuery UI's date picker - which is why we wrote our own data picker in the first place. It could be as simple as a z-index issue on your page, but I'd really need to see it to be able to debug it. If you could use http://live.datatables.net to show the issue (if you can't host your page yourself) then I can debug it that way.

    Do I need to use parallel js to work a simple order when clicking on a column?

    DataTables built in sorting works with ISO8601 format only. If you want to sort dates correctly on another format, then you need to use a sorting plug-in such as the EU sort one you have done. The Editor examples use MomentJS with our "Ultimate" date time sorting plug-in, which will sort basically any format.

    I agree that this has been a complex process and far from ideal - I'm sorry it hasn't been painless for you. Hopefully using our server-side libraries and the datetime input would mitigate most of the issues. Generator also provides options for date field formatting which shows it working with just a few clicks.

    Allan

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    I have no way to host. Putting on live are many dependent files and another, the main one that is data from the bd, has no way.
    I can send the used files zipped to you by email if applicable, then just test it in your environment.
    Is that possible?

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Tomorrow I will make a copy of the project, I will only separate the page with its files and try to upload it there on live.datatables

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    What zone is this live.datatable!
    I couldn't get it to work there and, with every attempt I made to delete what I had done, I created a new / 1. / 2, / 3, and so on. In addition to not being able to delete what I had done and creating a new one each time I try to delete it, the delete from live.datatable does not work, so please give a way to delete there because I don't want personal data mine there.
    Man, what the hell to mess with, every hour has something .... Business, instead of facilitating, makes it even more difficult!
    I will be forced to hire a hosting for me, just so I can put the files there for you to check the problem !?
    Imagine me presenting this to the company, if every little problem stays in this whole soap opera, my GOD!

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    I couldn't get it to work there

    Why not? What happens? Are you seeing console errors? What debugging did you do?

    http://live.datatables.net/ presents you with a simple working example. As you build on that example, it's a process of monitoring your own progress step by step.

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    I have several dependent files in the project, there are several. To do a test there, I would have to upload all of them on a server and link them I tried, but it only gives error.
    And another, this live.datatables is just a mess!
    Nobody said that he would have to register to be able to delete, now, it is full of tests there, because with every attempt I made to delete what I did, he created another editing id.
    Filth !

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Follow a link as you asked to view the problem.

    https://lmneto.com.br/xxx/

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Thank you for that, test case, that'll help to diagnose this problem. Now we can see the issue, please can you go back to mine and Allan's previous comments and change the field to be a datetime, with the correct formatting options for displayFormat and wireFormat.

    This is the correct way to go, and now we can see your site, we'll be able to understand what the problem was with that field.

    Colin

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Excellent - thank you for the link! Hoepfully you'll be able to understand why it is difficult for us to debug a page that we can't see. With this page I can indeed see the error with the date coming back in the incorrect format on edit.

    When the data is loaded initially it is done like this:

    {
        "data": [{
            "id": "1",
            "clipaccod": "1",
            "clipacnom": "NOME 1",
            "clipacenddsc": "XXX",
            "clipacendnum": "1",
            "clipaccompl": "XXX",
            "clipaccidade": "XXX",
            "clipacbairro": "XXX",
            "clipaccep": "xxx",
            "clipacuf": "XX",
            "clipacrg": "XXX",
            "clipaccpf": "XXX",
            "clipacdatnas": "02/06/2020",
            "clipacnac": "XXX",
            "clipactelfixo": "xxx",
            "clipactelcel": "xxx",
            "clipacemail": "xxx",
            "clipacusuario": null,
            "clipacsenha": null,
            "clipactipoconta": null,
            "clipacstatus": "A",
            "ultcod": "15"
        }, 
            ...,
            ]
    }
    

    So far, so good - but when the Edit is triggered the response from the server is:

    {
        "data": [{
            "DT_RowId": "row_6",
            "id": "6",
            "clipaccod": "6",
            "clipacnom": "NOME6",
            "clipacenddsc": null,
            "clipacendnum": null,
            "clipaccompl": null,
            "clipacbairro": null,
            "clipaccidade": null,
            "clipacuf": null,
            "clipaccep": null,
            "clipacrg": null,
            "clipaccpf": null,
            "clipacdatnas": "2020-06-22",
            "clipacnac": null,
            "clipactelfixo": null,
            "clipactelcel": null,
            "clipacemail": null,
            "clipacstatus": "A"
        }]
    }
    

    Hence why the date is then being shown as ISO8601 in the table after an edit.

    So the question is - what does tablecp.php contain (code wise)? It is different from where the data is being loaded initially (cp.php), so I'm guessing it might not have a get formatter defined for clipacdatnas?

    Allan

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Good morning Allan.
    in tablecp.php I have:
    Field :: inst ('clipacdatnas') -> validator ('Validate :: notEmpty'),
    Field :: inst ('clipacdatnas') -> setFormatter (Format :: dateFormatToSql ("d / m / Y")),

    However, with getFormatter it doesn't work.

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    And in cp.php I have:
    if ($ row_data ["clipacdatnas"]! == NULL) {
    $ data ['clipacdatnas'] = date ('d / m / Y', strtotime ($ row_data ["clipacdatnas"]));
    } else {
    $ data ['clipacdatnas'] = ''; // '00/00/0000';
    }

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Can you show me the full and unabbreviated cp.php file please?

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0
    edited June 2020
    <?php
        date_default_timezone_set("America/Sao_Paulo");
        require('config.php'); 
        //Receber a requisão da pesquisa 
        $requestData= $_REQUEST;    
        //Indice da coluna na tabela visualizar resultado => nome da coluna no banco de dados
        $columns = array( 
            //// 0 é o checkbox
            1 => 'id',
            2 => 'clipaccod',
            3 => 'clipacnom',
            4 => 'clipacdatnas',
            5 => 'clipacstatus',
        );
        
        $select_ultcod = "select (max(clipaccod)+1) as ult_cod from cp";
        $result_ultcod = mysqli_query($conn, $select_ultcod);
        $resultado_ultcod = mysqli_fetch_assoc($result_ultcod);
        $ult_codigo = $resultado_ultcod["ult_cod"]; 
    
        $select = "SELECT id,clipaccod,clipacnom,clipacdatnas,clipacstatus FROM cp where clipacstatus='A'";
        if(!empty($requestData['search']['value']) ) {   // se houver um parâmetro de pesquisa, $requestData['search']['value'] contém o parâmetro de pesquisa
            $select.=" AND (clipaccod LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacnom LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacdatnas LIKE '".$requestData['search']['value']."%' )";  ///// sempre a última condição
        }           
        $result = mysqli_query($conn, $select);
        $dados = array();
        while( $row_dados =mysqli_fetch_array($result) ) {  
            $dado = array(); 
            $dado['id'] = $row_dados["id"];
            $dado['clipaccod'] = $row_dados["clipaccod"];
            $dado['clipacnom'] = $row_dados["clipacnom"];
            //$dado['clipacdatnas'] = $row_dados["clipacdatnas"];
            if($row_dados["clipacdatnas"] !== NULL){
                $dado['clipacdatnas'] = date('d/m/Y',strtotime($row_dados["clipacdatnas"]));
            }else{
                $dado['clipacdatnas'] = ''; //'00/00/0000';
            }
            $dado['clipacstatus'] = $row_dados["clipacstatus"];
            $dado['ultcod'] = $ult_codigo;
            $dados[] = $dado;
        }
        $json_data = array(
            "data" => $dados,
        );
        echo json_encode($json_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    ?>
    

    Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Thank you - that doesn't look like the code that is returning the JSON data from cp.php though. For example your $dado array doesn't have a clipacemail property, but the JSON on your site does.

    That said - the clipacdatnas part of the code looks correct - it will parse and format the output correctly for the date. But as I say, that doesn't look like the code that is actually running.

    Allan

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0
    edited June 2020

    Alan, good morning.
    It's the same file, I just removed these fields to make the code smaller, but if you want to see the whole file it's there.

    <?php
        date_default_timezone_set("America/Sao_Paulo");
        //Receber a requisão da pesquisa 
        $requestData= $_REQUEST;    
        //Indice da coluna na tabela visualizar resultado => nome da coluna no banco de dados
        $columns = array( 
            //// 0 é o checkbox
            1 => 'id',
            2 => 'clipaccod',
            3 => 'clipacnom',
            4 => 'clipacenddsc',
            5 => 'clipacendnum',
            6 => 'clipaccompl',
            7 => 'clipaccidade',
            8 => 'clipacbairro',
            9 => 'clipaccep',           
            10 => 'clipacuf',
            11 => 'clipacrg',
            12 => 'clipaccpf',
            13 => 'clipacdatnas',
            14 => 'clipacnac',
            15 => 'clipactelfixo',
            16 => 'clipactelcel',
            17 => 'clipacemail',
            18 => 'clipacusuario',
            19 => 'clipacsenha',
            20 => 'clipactipoconta',
            21 => 'clipacstatus',
        );
        
        $select_ultcod = "select (max(clipaccod)+1) as ult_cod from cp";
        $result_ultcod = mysqli_query($conn, $select_ultcod);
        $resultado_ultcod = mysqli_fetch_assoc($result_ultcod);
        $ult_codigo = $resultado_ultcod["ult_cod"]; 
    
        $select = "SELECT id,clipaccod,clipacnom,clipacenddsc,clipacendnum,clipaccompl,clipaccidade,clipacbairro,clipaccep,clipacuf,clipacrg,clipaccpf,clipacdatnas,clipacnac,clipactelfixo,clipactelcel,clipacemail,clipacusuario,clipacsenha,clipactipoconta,clipacstatus FROM cp where clipacstatus='A'";
        if(!empty($requestData['search']['value']) ) {   // se houver um parâmetro de pesquisa, $requestData['search']['value'] contém o parâmetro de pesquisa
            $select.=" AND (clipaccod LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacnom LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacenddsc LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacendnum LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipaccompl LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipaccidade LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacbairro LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipaccep LIKE '".$requestData['search']['value']."%' ";          
            $select.=" OR clipacuf LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacrg LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipaccpf LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacdatnas LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacnac LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipactelfixo LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipactelcel LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacemail LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacusuario LIKE '".$requestData['search']['value']."%' )";  ///// sempre a última condição
        }           
        $result = mysqli_query($conn, $select);
        $dados = array();
        while( $row_dados =mysqli_fetch_array($result) ) {  
            $dado = array(); 
            $dado['id'] = $row_dados["id"];
            $dado['clipaccod'] = $row_dados["clipaccod"];
            $dado['clipacnom'] = $row_dados["clipacnom"];
            $dado['clipacenddsc'] = $row_dados["clipacenddsc"];
            $dado['clipacendnum'] = $row_dados["clipacendnum"];
            $dado['clipaccompl'] = $row_dados["clipaccompl"];
            $dado['clipaccidade'] = $row_dados["clipaccidade"];
            $dado['clipacbairro'] = $row_dados["clipacbairro"];
            $dado['clipaccep'] = $row_dados["clipaccep"];
            $dado['clipacuf'] = $row_dados["clipacuf"];
            $dado['clipacrg'] = $row_dados["clipacrg"];
            $dado['clipaccpf'] = $row_dados["clipaccpf"];
            //$dado['clipacdatnas'] = $row_dados["clipacdatnas"];
            if($row_dados["clipacdatnas"] !== NULL){
                $dado['clipacdatnas'] = date('d/m/Y',strtotime($row_dados["clipacdatnas"]));
            }else{
                $dado['clipacdatnas'] = ''; //'00/00/0000';
            }
            $dado['clipacnac'] = $row_dados["clipacnac"];
            $dado['clipactelfixo'] = $row_dados["clipactelfixo"];
            $dado['clipactelcel'] = $row_dados["clipactelcel"];
            $dado['clipacemail'] = $row_dados["clipacemail"];
            $dado['clipacusuario'] = $row_dados["clipacusuario"];  
            $dado['clipacsenha'] = $row_dados["clipacsenha"];
            $dado['clipactipoconta'] = $row_dados["clipactipoconta"];
            $dado['clipacstatus'] = $row_dados["clipacstatus"];
            $dado['ultcod'] = $ult_codigo;
            $dados[] = $dado;
        }
        $json_data = array(
            "data" => $dados,
        );
        echo json_encode($json_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    ?>
    

    Edited by Kevin:  Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Any solution !?
    So far I have tried and failed to resolve this.
    Soon it will expire and I can't show it to the company and we won't even buy anything!

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    Please use markdown to format your code. This will help the developers to see what you have. The instructions are noted at the bottom of the input area when you are posting:

    The developers are in the UK. I'm sure Allan will extend your Editor trial if needed.

    Kevin

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Forgive me, there are times that I forget.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Thanks for the code - I don't see any reason why it won't work I'm afraid. It appears to me from that code that the clipacdatnas should be returned formatted.

    Could you change it to contain:

    if($row_dados["clipacdatnas"] !== NULL){
       $dado['clipacdatnas'] = date('d/m/Y',strtotime($row_dados["clipacdatnas"]));
       echo "1- ". $row_dados["clipacdatnas"]."\n";
       echo "2- ". $dado["clipacdatnas"]."\n";
    }
    

    please? It will cause AN ERROR! Don't worry about that, I'm just interested in the text response from the server. You'll be able to see that in your browser's network inspector panel. Could you copy / paste it (unabbreviated) here, please?

    Thanks,
    Allan

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    1- 2020-06-02 2- 02/06/2020 1- 2020-12-02 2- 02/12/2020 1- 2020-06-04 2- 04/06/2020 {"data":[{"id":"1","clipaccod":"1","clipacnom":"NOME1","clipacenddsc":"XXX","clipacendnum":"1","clipaccompl":"XXX","clipaccidade":"XXX","clipacbairro":"XXX","clipaccep":"xxx","clipacuf":"XX","clipacrg":"XXX","clipaccpf":"XXX","clipacdatnas":"02/06/2020","clipacnac":"XXX","clipactelfixo":"xxx","clipactelcel":"xxx","clipacemail":"xxx","clipacusuario":null,"clipacsenha":null,"clipactipoconta":null,"clipacstatus":"A","ultcod":"15"}]}

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    That shows the response from the server is:

    "clipacdatnas": "02/06/2020",

    Is that from the edit action or the initial load? It looks like I might have got your two files mixed up - tablecp.php is the one which is doing the editing. Apologies. Can you show me the full and unabbreviated code in that file?

    Thanks,
    Allan

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    This code is for loading:

    <?php
        //Receber a requisão da pesquisa 
        $requestData= $_REQUEST;    
        //Indice da coluna na tabela visualizar resultado => nome da coluna no banco de dados
        $columns = array( 
            //// 0 é o checkbox
            1 => 'id',
            2 => 'clipaccod',
            3 => 'clipacnom',
            4 => 'clipacenddsc',
            5 => 'clipacendnum',
            6 => 'clipaccompl',
            7 => 'clipaccidade',
            8 => 'clipacbairro',
            9 => 'clipaccep',           
            10 => 'clipacuf',
            11 => 'clipacrg',
            12 => 'clipaccpf',
            13 => 'clipacdatnas',
            14 => 'clipacnac',
            15 => 'clipactelfixo',
            16 => 'clipactelcel',
            17 => 'clipacemail',
            18 => 'clipacusuario',
            19 => 'clipacsenha',
            20 => 'clipactipoconta',
            21 => 'clipacstatus',
        );
    
        $select_ultcod = "select (max(clipaccod)+1) as ult_cod from cp";
        $result_ultcod = mysqli_query($conn, $select_ultcod);
        $resultado_ultcod = mysqli_fetch_assoc($result_ultcod);
        $ult_codigo = $resultado_ultcod["ult_cod"]; 
    
        $select = "SELECT id,clipaccod,clipacnom,clipacenddsc,clipacendnum,clipaccompl,clipaccidade,clipacbairro,clipaccep,clipacuf,clipacrg,clipaccpf,clipacdatnas,clipacnac,clipactelfixo,clipactelcel,clipacemail,clipacusuario,clipacsenha,clipactipoconta,clipacstatus FROM cp where clipacstatus='A'";
        if(!empty($requestData['search']['value']) ) {   // se houver um parâmetro de pesquisa, $requestData['search']['value'] contém o parâmetro de pesquisa
            $select.=" AND (clipaccod LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacnom LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacenddsc LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacendnum LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipaccompl LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipaccidade LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacbairro LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipaccep LIKE '".$requestData['search']['value']."%' ";          
            $select.=" OR clipacuf LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacrg LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipaccpf LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacdatnas LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacnac LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipactelfixo LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipactelcel LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacemail LIKE '".$requestData['search']['value']."%' ";
            $select.=" OR clipacusuario LIKE '".$requestData['search']['value']."%' )";  ///// sempre a última condição
        }           
        $result = mysqli_query($conn, $select);
        $dados = array();
        while( $row_dados =mysqli_fetch_array($result) ) {  
            $dado = array(); 
            $dado['id'] = $row_dados["id"];
            $dado['clipaccod'] = $row_dados["clipaccod"];
            $dado['clipacnom'] = $row_dados["clipacnom"];
            $dado['clipacenddsc'] = $row_dados["clipacenddsc"];
            $dado['clipacendnum'] = $row_dados["clipacendnum"];
            $dado['clipaccompl'] = $row_dados["clipaccompl"];
            $dado['clipaccidade'] = $row_dados["clipaccidade"];
            $dado['clipacbairro'] = $row_dados["clipacbairro"];
            $dado['clipaccep'] = $row_dados["clipaccep"];
            $dado['clipacuf'] = $row_dados["clipacuf"];
            $dado['clipacrg'] = $row_dados["clipacrg"];
            $dado['clipaccpf'] = $row_dados["clipaccpf"];
            //$dado['clipacdatnas'] = $row_dados["clipacdatnas"];
            // if($row_dados["clipacdatnas"] !== NULL){
                // $dado['clipacdatnas'] = date('d/m/Y',strtotime($row_dados["clipacdatnas"]));
            // }else{
                // $dado['clipacdatnas'] = ''; //'00/00/0000';
            // }
    if($row_dados["clipacdatnas"] !== NULL){
       $dado['clipacdatnas'] = date('d/m/Y',strtotime($row_dados["clipacdatnas"]));
       echo "1- ". $row_dados["clipacdatnas"]."\n";
       echo "2- ". $dado["clipacdatnas"]."\n";
    }       
            $dado['clipacnac'] = $row_dados["clipacnac"];
            $dado['clipactelfixo'] = $row_dados["clipactelfixo"];
            $dado['clipactelcel'] = $row_dados["clipactelcel"];
            $dado['clipacemail'] = $row_dados["clipacemail"];
            $dado['clipacusuario'] = $row_dados["clipacusuario"];  
            $dado['clipacsenha'] = $row_dados["clipacsenha"];
            $dado['clipactipoconta'] = $row_dados["clipactipoconta"];
            $dado['clipacstatus'] = $row_dados["clipacstatus"];
            $dado['ultcod'] = $ult_codigo;
            $dados[] = $dado;
        }
        $json_data = array(
            "data" => $dados,
        );
        echo json_encode($json_data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    ?>
    

    This code is from the edition:

    <?php
    
    /*
     * Example PHP implementation used for the index.html example
     */
    
    // DataTables PHP library
    include( "DataTables.php" );
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    // Build our Editor instance and process the data coming from _POST
    $out = Editor::inst( $db, 'cp' )
        ->fields(
            Field::inst( 'id')->set(false), // ID is automatically set by the database on create //// getFormatter
            Field::inst( 'clipaccod' ),
            Field::inst( 'clipaccod' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'clipacnom' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'clipacnom' )->setFormatter( 'Format::UpperLetter' ),
            Field::inst( 'clipacenddsc' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'clipacenddsc' )->setFormatter( 'Format::UpperLetter' ),       
            Field::inst( 'clipacendnum' ),
            Field::inst( 'clipacendnum' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'clipaccompl' )->setFormatter( 'Format::UpperLetter' ),
            Field::inst( 'clipacbairro' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'clipacbairro' )->setFormatter( 'Format::UpperLetter' ),
            Field::inst( 'clipaccidade' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'clipaccidade' )->setFormatter( 'Format::UpperLetter' ),
            Field::inst( 'clipacuf' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'clipacuf' )->setFormatter( 'Format::UpperLetter' ),
            Field::inst( 'clipaccep' ),
            Field::inst( 'clipaccep' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'clipacrg' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'clipacrg' )->setFormatter( 'Format::UpperLetter' ),
            Field::inst( 'clipaccpf' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'clipaccpf' )->setFormatter( 'Format::UpperLetter' ),
            Field::inst( 'clipacdatnas' )->validator( 'Validate::notEmpty' ),
    
    
            Field::inst( 'clipacdatnas' )->setFormatter(Format::dateFormatToSql("d/m/Y")),
    
    
    
            Field::inst( 'clipacnac' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'clipacnac' )->setFormatter( 'Format::UpperLetter' ),
            Field::inst( 'clipactelfixo' ),
            Field::inst( 'clipactelcel' ),
            Field::inst( 'clipacemail' ),
            Field::inst( 'clipacstatus' )
    )
    
        ->process( $_POST )
        ->data();
    
    // On 'read' remove the DT_RowId property so we can see fully how the `idSrc`
    // option works on the client-side.
    if ( Editor::action( $_POST ) === Editor::ACTION_READ ) {
        for ( $i=0, $ien=count($out['data']) ; $i<$ien ; $i++ ) {
            unset( $out['data'][$i]['DT_RowId'] );
        }
    }
    
    // Send it back to the client
    echo json_encode( $out );
    
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Field::inst( 'clipacdatnas' )->setFormatter(Format::dateFormatToSql("d/m/Y")),

    It is missing a get formatter:

    Field::inst( 'clipacdatnas' )
      ->getFormatter(Format::dateSqlToFormat("d/m/Y"))
      ->setFormatter(Format::dateFormatToSql("d/m/Y")),
    

    should fix it.

    Allan

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    I don't believe Allan.
    I swear I was using these 2 functions, but I was using it the wrong way. I was putting a comma in each one and noticed that you sent without a comma between each of the two functions.
    Here's how I was doing:

    Field :: inst ('clipacdatnas') -> getFormatter (Format :: dateSqlToFormat ("d / m / Y")),
    Field :: inst ('clipacdatnas') -> setFormatter (Format :: dateFormatToSql ("d / m / Y")),
    

    Is that the cause of the problem !? If so, why !?
    And look, I sent this code at the beginning huh, it wasn't noticed ... lol

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Is that the cause of the problem !? If so, why !?

    It is defining two different fields there, rather than initialising just one and configuring it.

    And look, I sent this code at the beginning huh, it wasn't noticed ... lol

    I missed it in between all the other messages and code - apologies.

    Allan

  • lauromnetolauromneto Posts: 129Questions: 0Answers: 0

    Good afternoon Alan. Sorry to answer just now.
    No need to apologize Alan, I know, there were a lot of messages, lol ....
    So ... I see ...
    Boy, thank you very much, thank you. God bless.
    I will start other tests.
    A big hug.

This discussion has been closed.