Changing field type editor for specific rows/cells

Changing field type editor for specific rows/cells

Corado BarloccoCorado Barlocco Posts: 3Questions: 1Answers: 0

I have a one row table and best visualization was to transpose it.
I've done everything i need to manage it so now i have a table with many rows and 3 columns:
* id (hidden)
* field name
* field value

I can edit them and manage to save everything correctly but now i have a problem: i need some field values to be edited as a date field, some as a select2 type and some others as a text. Since while initing editor i can specify just one type for column, i can't set an editor specific for cell.

Is there a way i can set the editor field type for specific row? With datatable we can pass a function to the render method to change its behaviour dynamically, is it possible to do something similar with editor fields' type or is it possible at runtime via events hook (i looked for such solution but wasn't able to solve it)

Thanks in advance

Answers

  • Corado BarloccoCorado Barlocco Posts: 3Questions: 1Answers: 0
    edited October 2019

    I'd like to have your suggestion since you know the library, but i managed to solve my problem and here is my solution in pseudo code (please remember i'm using inline editing on a "transposed" table where my id column contains the fieldname since my row id is the fieldname):

    $('#myTable').on( 'click', 'tbody td.editable', function (e) {
    
                        //obtaining the current row fieldName for datatable instance
                        currentId = table.row( $(this).parent() ).data().fieldName
    
    
    if (lastIdClicked != currentId) {
    //then i've changed row then checking my rowId i decide to remove a field type and add another if needed
    if (currentId=='aDateField') {
    editor.clear('value');
    editor.add(
    {
                            label: "Value:",
                            name: "value",
                            type: "date"
                        };
    );
    }
    }
    
    

    This way i can dynamically change editor type on any click. I managed to use Select2 plugin this way

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    There isn't a way to dynamically change the field type I'm afraid. The closest would be to remove the field and then a new one as you have done.

    The only other option I can think of would be to initialise multiple instances of Editor, one with each of the field types required, then trigger the required Editor instance for each row. Would mean multi-row editing wouldn't work, but I guess it doesn't using the clear / add method either.

    Allan

  • John M.John M. Posts: 6Questions: 0Answers: 0

    I have a very similar use case to Corado and would like to second the wish for a simple way to set the field type per cell instead of per column.

    Unfortunately my scenario is a bit more complicated because I am using KeyTable to automatically trigger inline editing instead of using a click event handler. I am leveraging event handlers for KeyTable's 'key-focus' and the editor's 'open' events, which I might be able to work with for a solution.

    My lasting concern is that the cells for dates I would like a datepicker icon to always show, not just when that row or cell has focus.

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    My lasting concern is that the cells for dates I would like a datepicker icon to always show, not just when that row or cell has focus.

    You could use a rendering function to add an icon in.

    I'm afraid there is no change in the ability to dynamically change the type of a field. You'd still need to either remove the old one and then add a new field of the required type, or use multiple Editor instances and decide which one to use based on the field type.

    Allan

This discussion has been closed.