Editor Inline -> change individuell input to select -> loosing the eventlisteners

Editor Inline -> change individuell input to select -> loosing the eventlisteners

FleiFlei Posts: 10Questions: 4Answers: 0

Hi.
I use this example:
https://editor.datatables.net/examples/inline-editing/fullRow.html
in the first coloumn i have an select.
With this sellect i want to change <input> field of the second row

So
when in select in column 1 -> value=1 then same row in column 2 should be an select
when in select in column 1 -> value=2 then same row in column 2 should be an checkbox
when in select in column 1 -> value=2 then same row in column 2 should be an input

i realize it now like this

$("#table329").DataTable().off('click').off('key-focus').on( 'click', 'tbody td:not(:first-child)', function (e) {
// Focus on the input in the cell that was clicked when Editor opens
   editor329.one( 'open', () => {
    $('input', this).focus();
  });
    editor329.inline( $("#table329").DataTable().cells(this.parentNode, '*').nodes() );
setTimeout(function(){set_fields();},300);




function set_fields()
{
        type_id=$('#DTE_Field_type_id').val();
        if (type_id==2)
        {
            $('#DTE_Field_value1').parent().html('<select id="DTE_Field_value1"><option value="0"> -- </option></select>');
            $('#DTE_Field_value1').addClass('select-chosen select-chosen-search form-control');
         
        }else if (type_id==3)
        {
            $('#DTE_Field_value1').parent().html('<input id="DTE_Field_value1" type="text">');
        }
} ;

it works -> to change -> but also the INPUT and the SELECT looses there eventlisteners

is it possible to reinitial them or another easy way?

Thanks

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Yes, you are writing in entirely new elements there, so the event listeners applied to the previous elements, wouldn't work on these ones. Basically Editor has no idea that you've changed the input elements.

    What you need to do is use clear() to remove the previous input and then add() to add the new type. Unfortunately Editor doesn't have the ability to dynamically change an input type, which is why those two methods are needed. Using that approach, Editor will still be able to control the input / select elements.

    Allan

  • FleiFlei Posts: 10Questions: 4Answers: 0

    Hi.

    Thanks for Answer.

    Now i try

    editor329.clear( 'value1' );
    editor329.add( {
                        type:"select",
                        label: "value1",
                        name: "value1",
                        options: [{ label: "--", value: 0},{ label: "2", value: 2}]
                    }, 'type_id' );
    

    clear works fine - only this field is cleared
    with add -> whole row is clear -> i do it when inline edit is in progress.

    Thanks
    Thomas

  • FleiFlei Posts: 10Questions: 4Answers: 0

    Looks like add() is not for inline edit

Sign In or Register to comment.