editor migration from 1.4.2 to 1.5.2

editor migration from 1.4.2 to 1.5.2

crush123crush123 Posts: 417Questions: 126Answers: 18
edited November 2015 in Editor

I am continuing to develop a site which has been using datatables since 1.9.4 and editor since 1.3, and am now trying to consolidate the site and remove the older libraries.

I have some working pages using 1.4.2 which throw errors if i change to 1.5.2. can i ask

is it advisable to update and if so, is there a migration document I should be following ?

This question has accepted answers - jump to:

Answers

  • aaronwaaronw Posts: 89Questions: 3Answers: 4

    For Editor you can look at https://editor.datatables.net/upgrade/1.5/ . I'm not sure what version of DT Editor 1.5.X needs, though.

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

    Editor 1.5 requires at least DataTables 1.10.7 - although the latest release is always recommended.

    What are the errors you are seeing with 1.5?

    Allan

  • crush123crush123 Posts: 417Questions: 126Answers: 18
    edited November 2015

    Thanks Both

    On my ajax page, i am interecepting a value posted by the editor.

    the syntax for 1.4.2 is

    if ( (Editor::action( $_POST ) === Editor::ACTION_CREATE) || (Editor::action( $_POST ) === Editor::ACTION_EDIT)) {
            $membershipexpiresvalue = $_POST['data']['members']['MembershipExpiresEnd'];
    
    ....
    }
    

    and i get the error Undefined index: members in...

    I think the issue is down to the fact that multiple edits are now possible and I also need to pass in the row id, but haven't yet worked out how

    i just tried

    $_POST['data']['row_94']['members']['MembershipExpiresEnd'] as an example, and this seems to work, i just haven;t worked out how to retrieve the posted editor row id
    

    I also tried adding the legacyajax command to my page, but this didn't fix the issue

    • when i checked the console, the headers appear ok, but the preview and response are empty
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    You can use the legacyAjax option if you want Editor to use the old style. You noted it didn't work, but not what the error was that made it not work.

    However, if you have the time to, updating to the new style will hopefully be beneficial in the long term.

    Allan

  • crush123crush123 Posts: 417Questions: 126Answers: 18
    edited November 2015

    Using legacyAjax produced the correct headers, but preview and response are empty !?

    I would prefer to move to the new style, but can't easily recover the row id of the currently edited row. - I want to return

    $_POST['data']['DT_RowId']['members']['MembershipExpiresEnd']

    The only way i have managed to do this is

    if ( (Editor::action( $_POST ) === Editor::ACTION_CREATE) || (Editor::action( $_POST ) === Editor::ACTION_EDIT)) {
            $rowvalue = array_keys($_POST['data']);
            $rowid = $rowvalue[0];
            $membershipexpiresvalue = $_POST['data'][$rowid]['members']['MembershipExpiresEnd'];
    

    it seems to work, but looks a bit clumsy.

    So far then, i have managed to edit the ajax page to work with editor 1.5.2, and it causes no problem with create and edit.

    However i do get a problem with delete.
    The delete part works ok, but I have a submitSuccess event which throws an error on delete, which (i think) worked ok before - 'Cannot read property 'contacts' of undefined', presumably because the data returned is an empty array, as the row has just been deleted.

      editor.on( 'submitSuccess', function ( e, json, data ) {
        //console.log(data);
        var active = data.contacts.Active;
        var email = data.contacts.EmailAddress1;
    

    ...

    Assuming this is the reason, i can add a condition to this block to check if the data is undefined ?

        editor.on( 'submitSuccess', function ( e, json, data ) {
        //console.log(json.data);
        if (data != undefined) {
          var active = data.contacts.Active;
          var email = data.contacts.EmailAddress1;
    
    ...
    
    }
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    but preview and response are empty

    Ah - you are using the pre-built libraries? In which case, the ones which comes with 1.5 do not support the legacy format - only the new one. Which would explain that issue.

    I would prefer to move to the new style, but can't easily recover the row id of the currently edited row.

    The method you have used is certainly one option - if you want to work directly with the raw data it is probably the only option. Instead, what I would suggest is that you use server-side events which were introduced in 1.5 to help with exactly this sort of situation. I realise it is a bit more work to update the code to the new style, but if you try it, I think it will be worth it!

    Allan

  • crush123crush123 Posts: 417Questions: 126Answers: 18
    edited November 2015

    Thanks Allan,

    I was a bit hesitant to change to the server side events as the original code I had took me a while to get right, but following the example from your link, I got most of it working pretty quickly.

    I find it much easier when I can work to an example, and the one on the server side events page made it a lot easier for me.

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

    Super - that's great to hear!

This discussion has been closed.