Column with multiple types

Column with multiple types

russlevyrusslevy Posts: 15Questions: 6Answers: 0

Hi,

I have a table with one column Name and one column Value. The column value can take different fieldtypes: checkbox, date, text

I implemented it as following:

        var arrData = []
        var dataType = {1: 'text', 2: 'autonumeric', 3: 'autonumeric', 4: 'date', 5: 'checkbox'}
        for (i = 0; i < data.length; i++) {
            var value
            if (data[i].field_type == 5 && data[i].value == 1)
                value = '<input type="checkbox" checked="true">'
            else if (data[i].field_type == 5)
                value = '<input type="checkbox">'
            else if (data[i].value == null)
                value = ''
            else 
                value = data[i].value
            $('#tblCustomFields tbody').append('<tr><td>' + data[i].label + '</td><td data-editor-field="' + data[i].label + '">' + value + '</td></tr>')
            var object = {name: data[i].label}
            object.type = dataType[data[i]['field_type']]
            if (data[i].field_type == 2)
                object.autonumeric = {aSep: '', vMax: '9999999999.99999'}
            arrData.push(object)
        }
        //initialize editor
        customfieldsEditor = new $.fn.dataTable.Editor({
            fields: arrData
        })
        $('[data-editor-field]').not(function(){this.find('input')}).on('click', function (e) {
            customfieldsEditor.inline(this, {
                buttons: '_basic'
            })
        })

Does anyone have a better way of implementing? Thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    One option might be to use the add() and clear() methods to dynamically add and remove fields in the Editor form - then you can create / remove fields based on the require type.

    Allan

  • russlevyrusslevy Posts: 15Questions: 6Answers: 0

    Thanks!

This discussion has been closed.