New Editor Fail!

New Editor Fail!

rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

I upgraded my Editor libraries to take advantage of mjoin.

After doing that, mjoin works great for display, however, none of my tables can edit at all anymore.

Even if I back out the code to all working before mjoin, and then I just replace the libraries, the new ones make any in-line edit return empty data with no updates to the database. Switch the libs back and all is working again.

What is going on?

<?php $siteRoot = substr(__FILE__, 0, -strlen($_SERVER['SCRIPT_NAME']));
      include $siteRoot.'/login/include/datatables/php/lib/DataTables.php';

      use DataTables\Editor,
          DataTables\Editor\Field,
          DataTables\Editor\Format,
          DataTables\Editor\Join,
          DataTables\Editor\Upload,
          DataTables\Editor\Validate;

      Editor::inst($db, 'Booked_Trips', 'TripID')
          ->field(
                    Field::inst('TripID'),
                    Field::inst('OrderID'),
                    Field::inst('NumPass'),
                    Field::inst('NumBags'),
                    Field::inst('CostTip'),
                    Field::inst('Name'),
                    Field::inst('PickupTime'),
                    Field::inst('PickupLocation'),
                    Field::inst('DropoffLocation'),
                    Field::inst('VehicleType'),
                    Field::inst('CostTrip'),
                    Field::inst('CostExtras'),
                    Field::inst('CostTax'),
                    Field::inst('CostTotal'),
                    Field::inst('Mileage'),
                    Field::inst('Duration'),
                    Field::inst('Tolls'),
                    Field::inst('MapLink'),
                    Field::inst('Status')
                  )
          ->where('OrderID', $_REQUEST['order'], '=')
          ->process( $_POST )
          ->json();

The above works for display with either library, but only works for editing with the old library. How can I fix this?

Replies

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    I added this but saw no errors.
    error_reporting(E_ALL);
    ini_set('display_errors', '1');

    I tried 'legacyAjax': true, to the editor definition, but it did not seem to help.

    I looked up my old version and I think it is 1.4.2 (@version in to of editor.php)

    How do I find the version of my DataTables.php (it is missing @version)?

    Is the problem that I need to upgrade DataTables along with Editor? I fear that will lead to other problems... I am finally 100% done with this project other than the fact I need mjoin to complete the final step, which I completed, but that broke editing through out :(

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    The version can be found in the Editor.php file - there is a version parameter.

    You must update both the client-side and server-side at the same time. For example the 1.4 PHP libraries won't work with the 1.5 Javascript and vice-versa.

    Mjoin is actually a direct alias of the old Join class - I introduced Mjoin for naming consistency.

    Allan

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    Ok, I had to upgrade editor php's, js. css, and the same for datatables. After fixing a few headaches I'm on the latest version of everything and everything seems to be working.

    One question... how do I get rid of the new "undo changes" that appears in editor below every field? It is ugly (and it doesn't seem to do anything either).

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Update your CSS to the Editor 1.5.x CSS.

    That button will only do something if you are multi-row editing, and it should only be shown if you are multi-row editing.

    Allan

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    That's what I had read... but I had upgraded the CSS... I though I had upgraded everything. If that is for sure the issue though, I must be pointing to an old css, so thanks for confirming... I will track it down.

    One other note.... I was using localStorage tables per your example (as discussed on this forum before). One thing that broke during the upgrade is that those tables now append a new "random-number" on the end of each data-row. I was grabbing the data as-is and sticking it in my database on submit... but that broke and I ended up hack-fixing it by adding a Notes field to my database and letting my code stick your new numbers in there ;)

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    I have verified that I am using the latest css for both DataTables 1.10.10/media/css/ and from Editor PHP 1.5.4/css/... yet I am still getting the undo in both in-line edits as well as the editor window.

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0
    edited February 2016

    New issue, in responsive details expand section (<tr class="none">) I am getting [object Object] instead of my data.

    This works:
    {'data': 'OrderID'},

    This works:
    {'data': 'OrderID', 'render': function(d,t,r) {oid = d; console.log(oid); return oid;}},

    This works with <tr class="all"> but not <tr class="none">?
    {'data': null, 'render': function(d,t,r) {oid = d.OrderID; console.log(oid); return oid;}},

    The console.log shows my OrderID, but when I click the green-plus everything in there that uses multiple variables in a render function (therefore using data: null) renders as [object Object]. Note: I only get this error on one page (user orders), all the other pages work fine doing the exact same code (admin orders, affiliate orders), so I am very puzzled.

    Thanks for the help.

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    Here is another example... on this one page, this renders as just TripID without the button, but it works fine on other pages:

    {'data': 'TripID', 'render': function(data) {return data + ' <span class="pull-right"><button class="btn btn-xs btn-danger" onclick="canTrip(\'' + data +'\');">CANCEL TRIP</button></span>'}},

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    One thing that broke during the upgrade is that those tables now append a new "random-number" on the end of each data-row.

    I'd need a test case showing the issue to be able to debug it.

    yet I am still getting the undo in both in-line edits as well as the editor window.

    Can you give me a link to the page so I can debug it please for this one as well please.

    New issue, in responsive details expand section (<tr class="none">) I am getting [object Object] instead of my data.

    This one as well I'm afraid. I don't immediately see the issue in the above so I'd need to be able to debug it.

    Allan

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    NOTE: The first issue is no big deal, it's just that DT_RowId is now included and it wasn't before the upgrade. My fix works fine, so don't worry about it.

    THANKS for the offer to debug... To see the last issue you need to place a reservation. You can see the middle issue along the way.

    1) Go here: http://owlv2.u166.commercialvirtualtours.com/book/air/?faa=JFK&zip=4%20Beacon%20Way,%20Jersey%20City,%20NJ

    2) Click Book Now after the price loads.

    3) At the top make an account, for Flight chose any data and airline, and enter 0 for the flight.

    4) Click 'Verify' then click ''Proceed"

    5) You are now on the Trips page which has some DataTables. Under "Passenger List" click your Name, Phone#, or No SMS to see an inline-edit with "undo changes". It should be the latest css.

    6) Proceed to the end using credit-card # 5454-5454-5454-5454. Then click the "User Dashboard" button.

    7) If you click the green + you will see what I was talking about with [object Object] and console.log()

    Thanks again.

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    I fixed the CSS problem... I guess the new one is called "editor.dataTables.min.css" and my old one was called "dataTables.editor.min.css". I just renamed the new one and overwrote the old one with it.

    Just down to the last bug:

    Flight: [object Object]
    Passengers: [object Object]
    Stop's: [object Object],[object Object]
    Extra's:

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    The [object Object] means that DataTables is being given an object for the data for that cell.

    What is the return from paintFlight, paintPassengers, etc? It might be worth adding some debug for that. It should be just a string.

    Allan

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    p.s. Nice app :-)

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0
    edited February 2016

    Thanks :) Heavy use of your excellent product.

    The functions are returning a string (also you can see the functions at the end of the root document source).

    If you go into the user Dashboard and click the green + for your trip, you will see a column called TripID that just has the ID. ...but it is supposed to have a button and it does on a different page, same code.

    {'data': 'TripID', 'render': function(data) {return data + ' <span class="pull-right"><button class="btn btn-xs btn-danger" onclick="canTrip(\'' + data +'\');">CANCEL TRIP</button></span>'}},

    If I do this, the console.log is the "oid" string, but the table still renders [object Object]. It does it for each string too in the fields where it is a mjoin list... multiple object's.

    {'data': null, 'render': function(d,t,r) {oid = d.OrderID; console.log(oid); return oid;}},

    If I just change "data:null" to "data:OrderID", and change "d.OrderID" to just "d", then all works fine. Something very screwy is going on here.

    PS: I just noticed you removed the mandatory ':' from the green-plus details too. Good change for customizability (I've wanted to remove the :'s before myself), but now I gotta go back and add a bunch of :'s where I do want them :) Dang upgrades ;)

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    I have another non-important issue with both the old and new libraries...

    Like 3 of my 30 or so pages have tables on them that do not responsive-resize properly. They have a lot of columns, and it's like the table width gets set to all the columns before the responsive plugin kicks in. Then many columns get hidden, but the remaining columns stretch out beyond the limits of the screen like before the responsive plugin does its stuff.

    I have been able to fix it by doing this $('.table').width('100%'); before this $('#tbl'+name).DataTable().columns.adjust().responsive.recalc();

    The part that drive me insane is that each is a carbon-copy of 2 other pages, and very similar to 20 other pages, but most pages work fine without having to add $('.table').width('100%'); even pages with the exact same ton's of hidden columns.

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0
    edited February 2016

    I have updated the user dash so you can see what I mean... if you return to the User Dashboard and open a console, you will see your OrderID being logged, but under the green + the OrderID is [object Object]... but it would work fine if it was in the table and not in the responsive-details.

    // Allan:  works   {'data': 'OrderID'},   ...doesn't work...
                       {'data': null, 'render': function(d,t,r) {oid = d.OrderID; console.log(oid); return oid;}},
    

    EDIT: You can now search for Allan in the code to find it (the above is live code).
    Below is not in the code:

    // Also works   {'data': 'OrderID', 'render': function(d,t,r) {oid = d; console.log(oid); return oid;}},
    
  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    Newest live code that says it all...

    // Allan:  works   {'data': 'OrderID'},
    //         works   {'data': 'OrderID', 'render': function(d,t,r) {oid = d; console.log(oid); return oid;}},
    // doesn't work:
                       {'data': null, 'render': function(d,t,r) {oid = d.OrderID; console.log(oid); return oid;}},
    // ...but the console.log does...  what is going on?
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    As I'm looking at the page just now, the following code is being used for the Order ID column:

    {'data': null, 'render': function(d,t,r) {oid = d.OrderID; console.log(oid); return oid;}},
    

    The console shows IK5B-4A02 from that line, and that value is also what is shown in the "Order ID" Responsive child row.

    Is that not happening for you?

    Allan

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0
    edited February 2016

    What the!?!?!

    Yes, everything is working properly now. No [object Object] at all, even the mjoin lists work! (Now I need to figure out how I fixed that, cause it was still broken last time I checked it last-night... wth) I think maybe it is just due to me updating the responsive plugin code (it was named differently than the old version like the css, so I was still using the old responsive plugin until last night)

    Ok, new one... I have a page with a table that uses joins, and I want inline editing. I accomplished this by using my own SQL code for the DT, and your php libs for editor... but I don't let your php libs to return data after edit... I make it again myself.

    This worked fine before the upgrade. After the upgrade your libs changed a bit, and I have updated my function to work with the changes, and everything looks to be working just as it used to except for the fact that nothing gets edited!

    <?php $siteRoot = substr(__FILE__, 0, -strlen($_SERVER['SCRIPT_NAME']));
          include $siteRoot.'/login/include/datatables/php/lib/DataTables.php';
    
          /* Save Inputs */
          $region = isset($_REQUEST['region']) ? $_REQUEST['region'] : '0';
    //      $rule   = isset($_REQUEST['rule'  ]) ? $_REQUEST['rule'  ] : '';
    
          use DataTables\Editor,
              DataTables\Editor\Field,
              DataTables\Editor\Format,
              DataTables\Editor\Join,
              DataTables\Editor\Validate;
          
          //fix to return empty array if region is passed as ''
          if ($region == '') {echo '{"row":[]}';}
          else
           {Editor::inst( $db, 'Pricing_Rules', 'ID')
              ->fields(
                        Field::inst('ID'),
                        Field::inst('Created'),
                        Field::inst('Modified'),
                        Field::inst('Name')         ->validator('Validate::required'),
                        Field::inst('RegionID')     ->validator('Validate::numeric'),
                        Field::inst('BasePrice')    ->validator('Validate::numeric'),
                        Field::inst('BaseMiles')    ->validator('Validate::minMaxNum', array('min' => 0, 'max' => 250, 'message' => 'Please enter a number of Base Miles (0-250)')),
                        Field::inst('PricePerMile') ->validator('Validate::numeric')
                      )
              ->where( 'RegionID' , $region, '=')
    //          ->where( 'ID' , $rule, '=')     
              ->process( $_POST );
    //          ->json();
           }
    
    
    //NEW
          $ID = '';
          foreach($_POST['data'] as $key => $value)
           {if (substr($key, 0, 4) == 'row_')
             {$ID = $key;}
           }
    //end NEW
    
          if (isset($_POST['action']) && ($_POST['action'] == 'remove')) {echo '[]';}
          else
           {$sql    = 'SELECT CONCAT("row_", p.ID) AS DT_RowId, p.*,'.
                           ' COUNT(DISTINCT a.FAA) AS NumFAAs,'.
                        ' COUNT(DISTINCT a.ZoneID) AS NumZones'.
                      ' FROM Pricing_Rules p'.
                      ' LEFT JOIN Pricing_Airports a ON (p.ID = a.Air2Zone OR p.ID = a.Zone2Air)'.
    //old DT                  ' WHERE CONCAT("row_", p.ID)="'.$_POST['id'].'"'.
                      ' WHERE CONCAT("row_", p.ID)="'.$ID.'"'.
                      ' GROUP BY p.ID';
            require_once $siteRoot.'/api/include/setTable.php';
           }
    
    /* END...  do not add close php tag! */
    

    When passing this data from an inline edit, the edit is not performed. Before the version upgrade, this worked fine (just delete NEW section, and restore that one "old DT" line instead of the line after that, and it works great with the old libs)

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Is the data in the database correctly updated? The issue is that the SELECT shown above doesn't work? Is $ID what you would expect?

    You've got an SQL injection issue there by the way - if I were to set the id to be ';DROP TABLE ... there would be all sort of trouble :-).

    Allan

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0

    Yes, I know security is horrid currently (though setTable does some checks before running the $sql). I will need to revamp the API as soon as possible.

    My select works fine, but the data does not get updated anymore using the new libs!

    The joins in the select can be a pain with your PHP libs, especially when you need to edit and/or insert on a joined table... so I have the DataTable pull from that same select instead of using your php-libs, and then I have Editor use your php-libs without the join so it can apply the inline-edit updates... but in the old libraries, that was causing errors with it not returning every field... which is why in the posted file I muted the output and call the custom select after the edit. That made it work fine... until I updated everything.

  • rpmccormickrpmccormick Posts: 136Questions: 18Answers: 0
    edited February 2016

    Fixed it tonight finally...

    1) I had to delete the required validator for the Name since you no longer send it when in-line editing:

                        Field::inst('Name')      ,//   ->validator('Validate::required'),
    

    Is there a new way to do this? I want it to be required for New, but I need in-line edits to work as well.

    2) In my setTable.php function I changed the following line:

    //      echo '{"row":'.str_replace(array('[', ']'), '', json_encode($data)).'}';
          echo '{"data":'.json_encode($data).'}';
    

    ...much cleaner! :) I like the changes, I just wish I was faster about finding and fixing all the differences.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    1) I had to delete the required validator for the Name since you no longer send it when in-line editing:

    You can use the submit option of the form-options object to specify what data will be submitted from the form. That object can be passed into inline().

    Allan

This discussion has been closed.