Dependent field handler not invoked if multiple differing rows selected

Dependent field handler not invoked if multiple differing rows selected

d3d3 Posts: 8Questions: 1Answers: 0

Hi,

I've noticed that the dependent field handler (https://editor.datatables.net/reference/api/dependent()) does not get invoked if I have multiple rows selected that have differing values for the field in question.

This causes an issue if I am showing/hiding a field - the edit popup is shown in whatever state it was last left in last time it was shown.

I tried to put an example together below but it doesn't fully function due to the lack of server side data.  

https://live.datatables.net/qurowaqo/2/edit

However, taking the dependent handler from that example, it's supposed to hide the "Age" field if editing a "London" row:

editor.dependent('Office', function (val, data, callback, e) { return val === 'London' ? { hide: 'Age' } : { show: 'Age' }; });

If when creating a new row I set the office to "London", the "Age" field disappears. If was to subsequently shift-select a "London" row AND a "New York" row, then hit "Edit", the "Age" field would still be hidden on the edit popup that appears, because the dependent function was never invoked for this latest edit.

I propose that the dependent function is called even if multiple rows with differing values are selected, but the value of the field should be set to null if it differs across the selected rows. The handler could then be updated to deal with this scenario.

-David.

Replies

  • allanallan Posts: 63,262Questions: 1Answers: 10,423 Site admin

    Hi David,

    Many thanks for flagging this up. The issue here is that dependent() operates on the change event for a field's input. That event can be customised, but when multi-row editing and the values of a field are different, they cannot be written to the DOM input element. They need to be stored in an object, and thus the change event on the input never happens!

    I need to have a deep think about this - the multi-set currently has no knowledge of the dependent handler. Perhaps it should simply trigger the change event even although it wasn't writing the value - but this feels like a possible footgun. On change one might expect to read the value (indeed the value is passed into dependent()s callback function as you mention) and it would need the handler to be potentially a lot more complex that for a single row.

    That probably is the way to go about it...

    Allan

  • d3d3 Posts: 8Questions: 1Answers: 0

    Hi Allan,

    Thanks for the insight. Tricky one. It's not causing a major problem for us, though obviously it would be nice if a solution is possible. I'll leave it with you.

    -David.

Sign In or Register to comment.