can the new "data-editor-value" be used for inline editor ?

can the new "data-editor-value" be used for inline editor ?

seth9009seth9009 Posts: 48Questions: 9Answers: 2

I'm reading trough the release notes and i've seen the data-editor-value witch is fantastic ... but i'm not sure if it works for inline editor, on docs it says just standalone editor ... basically i have a HTML generated datatable and some cell values may have a prefix or suffix that should not really be edited with inline editor they are added from CMS and are the same for all columns so i would only need to edit the value that's why when i've seen the data-editor-value i thought this is awesome .. but it seems it does not work ... for inline editor or does it ?

what i've done is added like this

<td data-editor-value="100">100 km</td>

but when i click on field to edit in the input box i get 100 km instead of 100

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    The inline editor works with both table editing and standalone editing, but I'm afraid that the data-editor-value option only works with standalone (while it appears you are editing a table).

    If you want your user to submit an integer only, but to add km as a postfix, use a data renderer.

    Allan

  • seth9009seth9009 Posts: 48Questions: 9Answers: 2

    Thank you for your reply!

    yes i'm doing inline editing on a HTML generated datatable not JSON, i don't think i can still use data renderer or can i ?

  • seth9009seth9009 Posts: 48Questions: 9Answers: 2

    if i can't use data renderer on a HTML generated datatable can i use something like

    <td><span>100</span> km</td>

    and target from editor td > span not just td ?

  • seth9009seth9009 Posts: 48Questions: 9Answers: 2

    or there is a callback that i can use just before that input is generated in the td cell and populated with the cell value, like that i can grab the td value and strip down any postfix/prefix it may have

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    You can still use columns.render on a DOM sourced table. Here is a nonsense example: http://live.datatables.net/qelilowu/1/edit .

    Allan

  • seth9009seth9009 Posts: 48Questions: 9Answers: 2

    Thank you Allan for your example, i had no idea u could do that on HTML generated table, good to know in the future, however this time i took a different approach inspired by the new data-* tag added for standalone editor :) hope it will help someone, this is the code below

          $(document).on('focus', '.data.table > tbody > tr > td.focus', function(e) {
            var cellVal = $('.data.table .focus').data('value');
            $('.data.table .focus').find('input').val(cellVal);
          });
    

    and on td element i simply use data-value="whatever"

  • seth9009seth9009 Posts: 48Questions: 9Answers: 2

    now if i think about it i should put it in context :) here is the code again

        dtable.on('key-focus', function(e, datatable, cell) {
    
          $(document).on('focus', '.data.table > tbody > tr > td.focus', function(e) {
            var cellVal = $('.data.table .focus').data('value');
            $('.data.table .focus').find('input').val(cellVal);
          });
    
          editor.inline(cell.index());
    
        });
    
  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Awesome. Thanks for posting back with your code.

    Allan

This discussion has been closed.