Is the read only display field type editor plugin dynamic for EVERY row?.

Is the read only display field type editor plugin dynamic for EVERY row?.

washuit-iammwashuit-iamm Posts: 133Questions: 55Answers: 2

https://editor.datatables.net/plug-ins/field-type/editor.display

I am just now noticing that my data property is only ran ONCE for my editor instance. My hope was to craft a read only display for the field depending on the row data when the editor opens. Should we note this on the plugin docs?

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    edited January 2019

    Maybe I'm not understanding the problem description but I created this example that seems to work:
    http://live.datatables.net/guwafemu/8/edit

    Select the row with "Tiger Nixon" click edit. The Position (info) field will show "System Architect". You can make changes or not. After closing the editor click the "Change Tiger" button. Now Tiger's position is "Changed". Edit again and the position should show "Changed".

    craft a read only display for the field depending on the row data when the editor opens

    I'm guessing you are updating that field somehow?

    Please update or provide a test case replicating the issue.

    Kevin

  • washuit-iammwashuit-iamm Posts: 133Questions: 55Answers: 2

    Thanks for the sample and ultra-fast reply Kevin. My data callback is not running every time edit is invoked. I made some very small changes to the Display plugin so I will start investigating and report back straight away.

  • washuit-iammwashuit-iamm Posts: 133Questions: 55Answers: 2

    http://live.datatables.net/koluzafi/3/

    This is basically my problem. I need to display html but on get I MUST have the original data. So I made a tiny tweak to the plugin. You will notice data never runs again and the result is the same every time. Internally, something is going on I do not understand.

  • washuit-iammwashuit-iamm Posts: 133Questions: 55Answers: 2

    Here is it successfully working. http://live.datatables.net/figobete/3/edit

    Display whatever you want, while leaving the original data intact so it may be sent the server on edits.

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    I understand your problem description and see that the fields data function runs once. Seems the change you made to get is causing the issue.

    I'm not clear on what it is you are trying to achieve but I updated your test case by setting the get to the original and the set to this:

        conf._rawHtml = val.data;
        conf._div.html(val.html);
    

    The data function now runs each time. I added my button to update Tiger and the updated data/html is displayed in the edit form.

    http://live.datatables.net/lusewiri/1/edit

    If this isn't what you want then please detail what you are trying to accomplish.

    Kevin

  • washuit-iammwashuit-iamm Posts: 133Questions: 55Answers: 2

    @kthorngren see my last reply. Sorry, I replied like 3 times to your initial comment. I discovered your solution on my own and drove it home with also allowing submission of the original data. I still dont understand WHY this works BTW. I dont get what is special about _rawHtml.

  • washuit-iammwashuit-iamm Posts: 133Questions: 55Answers: 2

    So, big bug. Multi-editing is not going to fly here. I am working hard to find a workaround. It sucks that I can not get the field configuration inside the field.data callback. If I could, then I could easily switch on something like multiEditable == false. It seems like multi-editing is bypassing the getter on my plugin....

  • washuit-iammwashuit-iamm Posts: 133Questions: 55Answers: 2

    I am not super happy with this solution, but I "fixed" multiEditing with an editor event hook. http://live.datatables.net/lusewiri/5/edit

      editor.on('initEdit', function( e, node, data, items, type ){
        var myEditor = this;
    
        var positionField = myEditor.field('position');
        var isMultiEditing = positionField.isMultiValue();
        var positionFieldValues = positionField.multiGet();
    
        if(isMultiEditing){
    
          var multiSetRequest = {};
          for(fieldRowId in positionFieldValues) {
            var fieldValue = positionFieldValues[fieldRowId];
            multiSetRequest[fieldRowId] = fieldValue.data;
          }
    
          positionField.multiSet(multiSetRequest);
        }                  
      });
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    As Kevin mentioned, I don't really get what you are trying to achieve here. Could you describe the problem you are trying to solve (without any code) please? You really want to avoid using fields.data as a function if you can!

    Allan

  • washuit-iammwashuit-iamm Posts: 133Questions: 55Answers: 2

    @allan I want a display field with all sorts of fancy HTML (like a regular table, or an ordered list for example) BUT when Editor does an AJAX POST, I want the original NON HTML data to be sent back to my server. Even on multi-editing!

    The entire issue boils down to the fact that the Display plugin requires data to be a function if you want to display the data in any meaningful way (read: as HTML). If your data is a string then no big deal, but what if its an array? What if its a complex object and you want to show that data in a meaningful way with HTML?

    In short, I need Display to show the field data in fancy HTML but AJAX POST back the original object. How can you possibly achieve this without a data callback function? And why do you stress not to use fields.data as a function?

    The why:

    You might be asking why I would want a read-only display field to send back data. The answer is because our server-side API supports writing the data but we want to stub that feature out in the UI and instead show the data as an HTML table.

    Now take a look at the POST request payload from my Chrome Developer tools:

    I have my cake and can eat it too. Hacking my around this has been painful. IMO the Display plugin should perhaps have an HTML callback that when populated, supports all the above features.

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

    On an individual field level, it sounds very much like you would want a custom field plug-in here not a display plug-in. At that point if HTML is show, then you absolutely can just write it into the document and have the get function return the inner HTML (or the unmodified HTML string if you've kept a copy of it - usually in the conf object).

    Allan

This discussion has been closed.