I have an input field and a print button in a collection dropdown. The input field helps users to set their preferred title dynamically.
Since there are a couple of tables on the page, I was struggling to get the input field's value. But I managed to get it working with below code.
config.parent._collection[0].firstElementChild.value.trim();
Please is it how something like this should be handled or there is a better way?
Thanks.
Test Case: https://live.datatables.net/gidakera/1
The actual code is similar to this.
var table = new DataTable('#example', {
layout: {
topStart: {
buttons: [
{
extend: 'collection',
text: 'Export',
buttons: [
'<input type="text" maxlength="100" placeholder="Enter title">',
{
extend: 'print',
title: function (config, dt) {
return config.parent._collection[0].firstElementChild.value.trim();
}
}
]
}
]
}
}
});