Inline Editing for certain fields only

Inline Editing for certain fields only

greggreggreggreggreggreg Posts: 42Questions: 19Answers: 2

I have a table with inline editing. I can edit the field ok, but to save each change, i have to click off the datatable. If I select the datatable, I get a error:

uncaught exception: Unable to automatically determine field from source. Please specify the field name. For more information, please refer to https://datatables.net/tn/11

I assume the issue is that only certain fields can be edited onclick. BUt my onlick code is this:

$('#myTable').on( 'click', 'tbody td:not(:first-child)', function (e) {
editorSignIn.inline( this, {
onBlur: 'submit'
} );
} );

How can I change it so only certain fields are onClick

thanks

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    If you just want to stop specific columns being inline edited, you would modify the selector on the click to be more selective. Currently you have tbody td:not(:first-child), but this can be more (or less) restrictive.

    If you want to base it on the contents of a cell, you can do something like this. That's for bubble editing, but the same applies for inline.

    Colin

  • greggreggreggreggreggreg Posts: 42Questions: 19Answers: 2

    thanks Colin, how do I go about the first one? Being more restrictive.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    It depends on how you want to restrict the jQuery selector. What is it you want to do?

    Colin

  • greggreggreggreggreggreg Posts: 42Questions: 19Answers: 2

    I have a datatable with 5 fields, but I only want 3 of them to be editable.

    That part is working, but when I click on one of the non-editable fields I get the console error above.

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    Answer ✓

    Did you make any changes to try being more restrictive?

    You can use something like :nth-child(3) to keep from invoking the inline edit event handler for column 3. For example:
    http://live.datatables.net/hayojeci/1/edit

    The example removes the first column and third column from the selectors for inline editing. It uses:

      $('#example').on('click', 'tbody td:not(:first-child, :nth-child(3))', function() {
        editor.inline(this);
      }); 
    

    Kevin

  • greggreggreggreggreggreg Posts: 42Questions: 19Answers: 2

    perfect, thanks

This discussion has been closed.