Set initial dropdown value to current cell value when editing

Set initial dropdown value to current cell value when editing

CrlotronCrlotron Posts: 16Questions: 5Answers: 0

Believe it or not, I'm making progress beyond the issues I'm bringing up here :D Thanks in advance to the great community that helps keep me moving forward!

I'm building an application where inline editing is needed. Some of the fields should be drop downs. My edit button correctly populates the dropdown options (hard coded in example, but pulled using ajax in my actual application). The problem I'm encountering is that when a cell turns into a dropdown, its value is overwritten. I tried to pass the current value in similarly to how it works for an input field, but no love. I've searched and tried different implementations without success for a few hours so I figure I'll check in with the experts.

Any help in setting the initial value of the dropdown to the current value of the cell would be most appreciated. Thank you.

http://live.datatables.net/nugudefa/7/edit

This question has an accepted answers - jump to answer

Answers

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

    The simplest way to use inline editing is to use Editor - see example here. There you can specify fields.def to define a default,

    Colin

  • CrlotronCrlotron Posts: 16Questions: 5Answers: 0

    Hey colin,
    Editor looks like a fantastic plugin and I enjoyed its ease of use for a few days of the trial. While Allan has priced his work fairly, I unfortunately can't afford it (single income, four kids, etc). Ironically, my actual application is a self-hosted budget :p

    I'll keep exploring ways to do this manually, but I do appreciate the suggestion.

  • kthorngrenkthorngren Posts: 21,352Questions: 26Answers: 4,955
    Answer ✓

    You can add the selected attribute to the options list. Look at the fnCreateDropdown function in this updated example:
    http://live.datatables.net/nudinebu/1/edit

    You will want to use the cell().data() API to update the Datatables cache with the updated data.

    Kevin

  • CrlotronCrlotron Posts: 16Questions: 5Answers: 0

    Thanks Kevin. I was kludging together a far more complicated/less readable solution. Appreciate your help, as always. I'll read the linked docs to figure out how to separately update the cache.

Sign In or Register to comment.