How can I disable inline edit of a cell (field) for a subset of rows; but enable edit for the rest?
How can I disable inline edit of a cell (field) for a subset of rows; but enable edit for the rest?

I'm using the inline edit feature that allows my users to update a specific cell (Quantity) in each row displayed. The rows are sorted by date and will have days in the past present (up to 6 days) and 50 days into the future. I've inline edit is working correctly but I need to make a change for a new requirement.
The requirement is the user can change the Quantity for any row in the future, but not today or the past.
Best solution would prevent the user from entering a Quantity value for rows in the past and today; if that's not possible, next solution could allow the edit but display a "Can't update values for today or past" and refresh the Quantity with the original value.
Unclear how best to proceed - please advise.
I'm using Datatable 1.10.15 (along with all the plugins associated with the release) and Editor 1.6.3
This question has an accepted answers - jump to answer
Answers
The key here is the event handler where you call the
inline()
method. Let's take this example - it uses:But say I don't want to allow inline editing of any row where the salary is > 500'000:
i.e. it simply doesn't call
inline()
if my condition isn't met.Regards,
Allan
No luck after adding the click event - the cell can be edited still for today and past rows. Here's what I added:
Your thoughts on what to try next?
Note - the current code I have was not using the table click event at all. When I create the editor instance, I specify what columns (fields) can be edited or read only. The editor was handling the fields correctly (edit/can't edit). Unclear if I now have a mix of approaches (table click event code I added with editor events). Below is the code for creating editor instance.
Other observation, I noticed with the click event added, I get different behavior for the field. Primarily when entering data - before I could select a field and start typing. Now it appends to the end the characters being entered. Which probably indicates the mix approaches is having an unwanted change in behavior.
You say you added the click event - what were you using before to activate the inline editing?
Thanks,
Allan
I'm assuming the option for keys on the table create to have an editor is the magic. I previously posted the logic for the editor setup - that's the function called from this one below. Keep in mind that the user selects from a drop down on the web page a cost center of interest. That causes the populateView() to be called. Each cost center will have different number of columns, with a subset of them consistent for all.
The table create logic looks like this:
function populateView() {
Ah! Yes - if you are using KeyTable, then it will call
inline()
for you.What to do is ignore what I suggested about using a click event listener before in that case... We still need some logic to decide if inline editing should activate or not, but now we'll do it in
preOpen
:Returning
false
frompreOpen
will cancel the editing view from displaying.Regards,
Allan
That works. Thanks. Onward and upward