Custom field type plugins and inline editing
Custom field type plugins and inline editing
I'm currently putting together a datatable containing standard text fields and a custom field plugin that displays a form text input + dropdown list on inline edit.
Using inline edit on the standard text fields work correctly -- I can see the callback function that I've assigned to the ajax
option is being called, and the new value is then displayed when the editor is closed. This doesn't seem to be the case with the custom plugin -- the callback is never called. In addition, assigning a dummy return value to the get function does not seem to result in it being displayed when the inline editor is closed. Have I misinterpreted how it works? I've placed an example of what has been done below.
_fieldTypes.power = {
create: function (field, id) {
var that = this;
field._enabled = true;
field._input = $(
'<div class="input-group">' +
'<input type="text" class="form-control" aria-label="...">' +
'<div class="input-group-btn">' +
'<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-menu-down"></span></button>' +
'<ul class="dropdown-menu dropdown-menu-right">' +
'<li name="absolute" value="0"><a href="#">Absolute</a></li>' +
'<li name="relative" value="1"><a href="#">Relative</a></li>' +
'</ul>' +
'</div><!-- /btn-group -->' +
'</div><!-- /input-group -->)')[0];
$('ul li', field._input).click(function (e) {
e.preventDefault();
});
return field._input;
},
get: function (field) {
return "hello world!";
},
set: function (field, val) {
}
};
})(jQuery, jQuery.fn.dataTable);
editor = new $.fn.dataTable.Editor({
ajax: function (method, url, d, successCallback, errorCallback) {
var output = {data: []};
if (d.action === 'edit') {
// Update each edited item with the data submitted
$.each(d.data, function (id, value) {
row = $('#wo').DataTable().row('#' + id).data();
$.extend(row, value);
output.data.push(row);
});
}
// Show Editor what has changed
successCallback(output);
},
table: "#wo",
fields: [{
name: "name"
}, {
name: "power",
type: "power"
}
]
});
Answers
I have the same problem with my custom autocomplete input...any resolutions at all?
There shouldn't be any difference between how a field works inline compared to the main form. If it works okay it should work okay inline - if that is not the case, can you link to a test page showing the issue so it can be debugged please?
Thanks,
Allan
Thanks Allan,
Unfortunately I can not provide a link to that page, as it would require authentication, (you probably get that a lot). I do have a debug for it, though I don't know how much that will help: http://debug.datatables.net/urenic
Basically here is my custom field type:
Here is my editor instance:
I am enabling inline edit:
I am trying to submit from the autocomplete input upon using 'enter' key, as it does with all other inputs. I would expect the submit from that action would allow the ajax to be called and subsequently perform the "data.action === 'edit'" portion of the above logic. But that never happens, it only works for regular inputs, not the custom field type I implemented.
Hoping that made any sense for you. Thanks.
Any ideas? Thanks
Sorry for the delay in replying - I completely missed your first reply!
What is the AutoComplete library you are using? I'm wondering if it might be swallowing the return key.
I've just tried my jQuery UI AutoComplete integration for Editor and it appears to take the return key okay when entering a value inline.
Internally Editor does this for the return key handling:
i.e. it will only work on
input
elements (which you have) and it needs to be able to see thekeydown
event. Is that isn't propagated up the DOM tree then it wouldn't be able to see it.Allan