different value on edit from display

different value on edit from display

seth9009seth9009 Posts: 37Questions: 7Answers: 2

I have implemented datatables with editor on a table, data comes from server side processing, some columns have extra data for example in DB i'll store 100 but on table i'll display 100 km the "km" comes from another setting in php, what i'm trying to achieve is have the datatables display 100 km but on inline edit to show 100, now i've seen this example

$('#example').DataTable({
ajax: {
        url: "../php/staff.php",
        type: "POST"
    },
    serverSide: true,
    columns: [
        { data: "first_name" },
        { data: "last_name" },
        { data: "position" },
        { data: "office" },
        { data: "start_date" },
        { data: "salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) }
    ]
});

and i've added to my JSON a new field "salary_display" and use it like this

        { data: "salary", render: "salary_display" }

but it does not work ... any ideas how it can be done ?

Thanks,
Claudiu

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 41,522Questions: 1Answers: 5,198 Site admin
    Answer ✓

    You can use the columns.editField option to tell Editor which field should be edited when inline editing is triggered (which I presume you are using)?

    Allan

  • allanallan Posts: 41,522Questions: 1Answers: 5,198 Site admin
    Answer ✓
    {
      data: 'salary_display',
      editField: 'salary'
    }
    
  • seth9009seth9009 Posts: 37Questions: 7Answers: 2

    Thanks Allan, this worked fine, i've used editField too this morning however not in the right combination it seems because i could not make it work.

    i have 3 other issues with this if u can help pls ..

    1) after inline edit the input field hangs, like i click on a cell i do my edit then click away on page the input is still open if i click again on page then the input closes so i need to do 2 clicks for the input to disappear .. any ideas ?

    2) if i'm editing a cell close it and then try to click on it again to edit it does not work anymore, any other cell works fine, but the the cell i just edited

    3) is there a way to define a certain column to open in bubble rather than inline ? i have some that are checkboxes, radios or multiselect and they look better in bubble rather than inline.

    Thank you very much!
    Claudiu

  • allanallan Posts: 41,522Questions: 1Answers: 5,198 Site admin

    1) after inline edit the input field hangs

    This suggests that the server is not responding with JSON in the format that Editor expects.

    2) if i'm editing a cell close it and then try to click on it again to edit it does not work anymore

    If you are using onBlur: 'submit' then it will likely be the same as issue 1. If not, then I would need a test case showing the issue as my examples don't appear to show that.

    3) is there a way to define a certain column to open in bubble rather than inline ?

    Yes, its all to do with the selector. You are using an event handler such as $(...).on( 'click' ... ) to call the inline() method. You would simply modify that or use a different event handler with a suitable selector to call the bubble() method. For example you might use columns.className to add a class to the cells to indicate if you want bubble or inline editing for the column and adjust your selector as required.

    Allan

  • seth9009seth9009 Posts: 37Questions: 7Answers: 2

    1 and #2 my response is in the correct format and i'm using the onBlur: 'submit' also i'm not getting any errors that's why it makes this even weird .. anyway your examples works fine so i guess it's something on my end, or a bug but that's kind of hard to pinpoint without an error ..

    3 that worked like a charm, thanks! :)

    Kind regards,
    Claudiu

  • allanallan Posts: 41,522Questions: 1Answers: 5,198 Site admin

    Hi Claudiu,

    If you have a link to a page showing the issue, I can take a look at it and see if I can spot anything.

    Allan

Sign In or Register to comment.