Dependent Function Fires when other fields clicked
Dependent Function Fires when other fields clicked
Scott Bowers
Posts: 13Questions: 2Answers: 0
I tried to create a live example with inline editing and no luck, the inline just wouldn't work. I have a table, with inline editing setup. I have a couple dependent functions. One has an ajax call in it and I noticed that when I click in a different cell that also has a dependent function both dependent function fire off. They end up firing back and forth just from clicking in the cell. Why would that happen.
dependent function 1:
this.editor.dependent("attributes.AVG_MSTR",dojo.hitch(this,function(val,data,callback){
if(val == data.row.attributes.AVG_MSTR) callback({});
else{
some code....
callback(data);
}
})),
dependent function 2
this.editor.dependent("MAP_AGCY_CROP_ID", dojo.hitch(this, function(val,data,callback) {
if(val === "" || (val === data.row.attributes.MAP_AGCY_CROP_ID)) callback({});
else{
do bunch of ajax stuff then callback(data);
},
This discussion has been closed.
Replies
Not sure about your problem but here is a basic Inline Editor example you might be able to use for a test case:
http://live.datatables.net/vagapezu/1/edit
Kevin
Here, http://live.datatables.net/vagapezu/6/edit click any field to edit and view the console, the Name dependent function fires no matter what cell you click in. Shouldn't that only fire if you change the Name column? So, what is happening then when you have multiples of these functions, you are having functions firing all over the place when someone click a cell. This is not good if one of those is an ajax call.
Hi,
It triggers as soon as editing starts because the value of the field is set. It has to be called at that point so the form can be synced up to the value that is being edited.
Keep in mind that with inline editing, the whole form is actually placed into edit mode - although only a single field is visibly editable, you could use the API to update the other fields if you needed.
Allan
That renders the dependent function kind of useless when using inline editing as it doesn't matter what you make dependent. All functions trigger no matter what you edit. This can cause circular loops and if you have Ajax calls in any of them you can clog up your browser. I did add some logic to check for a few things:
There is one option in Editor that might be of some help here - the
scope
property ofform-options
. By default it is set torow
which causes the whole row to be placed into editing mode. But you could set it to becell
which might address what you want here.But you need to be aware that if you use that option, you can't edit the other cells in the row - which is why it defaults to
row
(I did actually have it default tocell
back when I first introduced that option, but it caused all sorts of support requests!).Allan
Thanks Allan, I will give this a try.