Is it possible to make fields only addable, and not editable? when using Editor

Is it possible to make fields only addable, and not editable? when using Editor

gixxy22gixxy22 Posts: 15Questions: 7Answers: 1

I would like a the ability to make only certain fields editable, either when editing or inline-editing. I would like the fields to be populate on adding, but make them un-editable.

Is it possible?

thanks

This question has an accepted answers - jump to answer

Answers

  • gixxy22gixxy22 Posts: 15Questions: 7Answers: 1

    I've managed to make inline-editing available for only certain fields by doing this:

    ....
     columns: [
                        {"data": "id"},
                        {"data": "employee_id"},
                        {"data": "first_name", className: 'editable'},
                        {"data": "last_name", className: 'editable'},
                        {"data": "occupation", className: 'editable'},
                    ],
    ......
    $('#table').on( 'dblclick', 'tbody td.editable', function (e) {
       editor.inline( this );
    } );
    

    but cant work out how to do with for standard editing/multi row editing

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

    Populated by the user on create, or by the database?

    Allan

  • gixxy22gixxy22 Posts: 15Questions: 7Answers: 1

    sorry im not quite sure what you're asking.

    I would like the user to be able to create fieldA & fieldB values, but only be allowed to edit fieldB values

  • gixxy22gixxy22 Posts: 15Questions: 7Answers: 1

    Basically this: https://editor.datatables.net/reference/option/fields.multiEditable

    But an option for single rows

  • gixxy22gixxy22 Posts: 15Questions: 7Answers: 1
    Answer ✓

    figured it out!

     //disable editing
    editor.on('initEdit', function() {
      editor.hide('employee_id');
    });
    

    to remove the field

    or

     //disable editing
    editor.on('initEdit', function() {
      editor.disable('employee_id');
    });
    

    to grey it out

  • gixxy22gixxy22 Posts: 15Questions: 7Answers: 1

    worth noting to anyone else, that this needs to follow in order to reshow the field on initCreate

    editor.on('initCreate', function() {
       editor.show(); 
    });
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Super - thanks for posting back! Good to hear you've got it working.

    Allan

Sign In or Register to comment.