Maybe dumb question - how to add columns when user click "add" to create new row

Maybe dumb question - how to add columns when user click "add" to create new row

mkleinoskymkleinosky Posts: 46Questions: 6Answers: 5

I have datatable with some rows displayed but not editable.
When user clicks TableTools "Add" button I want them to be able to able to fill in the columns which are not editable on rows that exist....
In other words, once they enter data in a new row for a particular column (ed. District) they cannot change it.

In other words - normal editing is just to edit one column, but add requires entering a few more columns
does this make sense?
Can it be done? or better to have a separaet complete program/Datatable/Editor for this?

Replies

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

    If I understand correctly, I would suggest you using initCreate and initEdit with the enable() and disable() methods.

    For example:

    editor.on( 'initCreate', function () {
      editor.enable( 'field5' );
      editor.enable( 'field6' );
      editor.enable( 'field7' );
    } );
    
    editor.on( 'initEdit', function () {
      editor.disable( 'field5' );
      editor.disable( 'field6' );
      editor.disable( 'field7' );
    } );
    

    Is that what you are looking for?

    Allan

  • mkleinoskymkleinosky Posts: 46Questions: 6Answers: 5

    I think so - trying it now

  • mkleinoskymkleinosky Posts: 46Questions: 6Answers: 5
    edited March 2015

    Almost got it.

    $('#aeecs').on( 'initCreate', function () {
    editor.enable( 'District' );
    } );

    $('#aeecs').on( 'initEdit', function () {
    editor.disable( 'District' );
    } );

    • When I click "New" District is indeed in the Create form
    • if I instead of completing the add new record, select a row and click "Edit" - the filed "District" is on the edit form still
  • mkleinoskymkleinosky Posts: 46Questions: 6Answers: 5
    edited March 2015

    So I can add the field to add/edit form, but my disable code is not working

    $('#aeecs').on( 'initCreate', function () { editor.enable( 'District' ); } );

    $('#aeecs').on( 'initEdit', function () { editor.disable( 'District' ); } );

  • mkleinoskymkleinosky Posts: 46Questions: 6Answers: 5

    it is close enough for now, I can allow them to edit

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

    If you don't want to show the field at all, use hide() and show().

    What is the field type for District? Is it a plug-in?

    Allan

  • mkleinoskymkleinosky Posts: 46Questions: 6Answers: 5

    district is just a varchar/text input - thanks!

This discussion has been closed.