Editor select and chosen plugin
Editor select and chosen plugin
I am trying to find a way to dynamically pass a value, previous_tenant_id, from the currently being edited row into my chosen select option list for both inline editing and normal editing.
I know how to get the previous_tenant_id for both forms of editing like so,
// get active previous_tenant_id
editor.on('preSubmit', function(e, data, action) {
if (action === 'edit') {
var rowData = table.row(this.modifier()).data();
if (typeof rowData != "undefined") {
id = rowData.cms_module_system_tenancies.Id;
previous_tenant_id = rowData.cms_module_system_tenancies.tenant_id;
}
}
});
// get active previous_tenant_id inline
$('#cms_module_system_tenancies').on( 'blur', 'td', function () {
var tr = this.parentNode;
editor.inline( this );
editor.one( 'preSubmit', function ( e, data ) {
data.rowData = table.row( tr ).data();
id = data.rowData.cms_module_system_tenancies.Id;
previous_tenant_id = data.rowData.cms_module_system_tenancies.tenant_id;
});
});
But I cannot figure out how to pass this value to my chosen select option list when that row has been selected.
I found this forum post https://datatables.net/forums/discussion/25855/with-chosen-plugin
// Get the select element
var select = $('select', editor.field('myFieldName').node() );
.. add options to the list / manipulate the select list ...
// Tell Chosen to update
select.trigger('chosen:updated');
But, I cant get the option list to update. Has anyone tried or achieved this who would be happy to share code?
Thanks
Replies
I don't know if this is correct but it seems to work initially.
However, I do end up with a long list of new options, I guess I need to remove the previous last new item before adding a new one.
Sorry - I thought I'd replied to this question on Friday - apparently not!
What you have looks good - you might need to clean out the
select
list first if required.Did you try using the
update
method of the plug-in type as well? Or do you not what it to do a full update?Allan