[Editor] How to hide field on [Map CSV fields]?

[Editor] How to hide field on [Map CSV fields]?

AddupAddup Posts: 11Questions: 5Answers: 0
edited September 2020 in Free community support

I'm trying to hide a field on this modal?

selectEditor.create({
title: 'Map CSV fields',
buttons: 'Import '+csv.length+' records',
message: 'Select the CSV column you want to use the data from for each field.'
});

How do I do it?

I have only been able to hide a field on but not on selectEditor.create()

editor.on('initCreate', function() {
editor.show(); //Shows all fields
editor.hide('FirstName');
});

THANKS!

Answers

  • allanallan Posts: 63,186Questions: 1Answers: 10,411 Site admin

    Your question is presumably related to this example?

    The columns used for the mapping are added by this block:

        for ( var i=0 ; i<fields.length ; i++ ) {
            var field = editor.field( fields[i] );
     
            selectEditor.add( {
                label: field.label(),
                name: field.name(),
                type: 'select',
                options: header,
                def: header[i]
            } );
        }
    

    so if you didn't want a column, you could add an if condition in there to not add it.

    Allan

  • AddupAddup Posts: 11Questions: 5Answers: 0

    Correct, But I still need that excluded field on the "edit" as well as in the table

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Yep, so on the initEdit you would remove that field with field().hide(). That would do the trick,

    Colin

  • AddupAddup Posts: 11Questions: 5Answers: 0

    Thanks a lot, Colin, one last question, How would you add an if statement in the for loop to exclude 'phoneNumber' field from the .add()?

  • AddupAddup Posts: 11Questions: 5Answers: 0

    SOLUTION:

    var selectEditor = new $.fn.dataTable.Editor();
    var fields = editor.order();

    const filteredArray = fields.filter((fields) => fields !== 'gender')
    console.log(filteredArray) <--- new array:: HAY!

    for ( var i=0 ; i<filteredArray.length ; i++ ) {
    var field = editor.field( filteredArray[i] );
    selectEditor.add( {
    label: field.label(),
    name: field.name(),
    type: 'select',
    options: header,
    def: header[i]
    } );
    }

This discussion has been closed.