Can't search for values in Textboxes if the column hasn't been sorted yet
Can't search for values in Textboxes if the column hasn't been sorted yet
I'm having basically the same problem as this guy http://datatables.net/forums/discussion/2723/sorting-on-input-fields/p1 but no one ever proposed a solution and I do need one.
When the page loads I can't search any values in the datagrid that are IN a textbox. If I sort a column, I can then search any values in textboxes ONLY IN THAT COLUMN. I would have to manually sort all the columns to be able to search in all of them. I am assuming this is due to the way the datatables update itself after a sort. Is there any way to have it do that update after the page is loaded or programatically auto-sort all the columns so that all textboxes in all columns are searchable as soon as the page is loaded?
Below is my code
[code]
$('.datagrid').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": '<"top"fl>rt<"bottom"ip><"clear">',
"aoColumns": [
null,
{ "sSortDataType": "dom-text" },
{ "sSortDataType": "dom-text", "sType": "numeric" },
{ "sSortDataType": "dom-text" },
{ "sSortDataType": "dom-text", "sType": "numeric" },
{ "sSortDataType": "dom-text" },
{ "sSortDataType": "dom-text", "sType": "numeric" },
{ "sSortDataType": "dom-text", "sType": "numeric" },
{ "sSortDataType": "dom-text", "sType": "numeric" },
null]
});
[/code]
When the page loads I can't search any values in the datagrid that are IN a textbox. If I sort a column, I can then search any values in textboxes ONLY IN THAT COLUMN. I would have to manually sort all the columns to be able to search in all of them. I am assuming this is due to the way the datatables update itself after a sort. Is there any way to have it do that update after the page is loaded or programatically auto-sort all the columns so that all textboxes in all columns are searchable as soon as the page is loaded?
Below is my code
[code]
$('.datagrid').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sDom": '<"top"fl>rt<"bottom"ip><"clear">',
"aoColumns": [
null,
{ "sSortDataType": "dom-text" },
{ "sSortDataType": "dom-text", "sType": "numeric" },
{ "sSortDataType": "dom-text" },
{ "sSortDataType": "dom-text", "sType": "numeric" },
{ "sSortDataType": "dom-text" },
{ "sSortDataType": "dom-text", "sType": "numeric" },
{ "sSortDataType": "dom-text", "sType": "numeric" },
{ "sSortDataType": "dom-text", "sType": "numeric" },
null]
});
[/code]
This discussion has been closed.
Replies
[code]
$.fn.dataTableExt.afnSortData['dom-text'] = function (oSettings, iColumn) {
var aData = [];
$('td:eq(' + iColumn + ') input', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
aData.push(this.value);
});
return aData;
}
[/code]
http://datatables.net/release-datatables/extras/AutoFill/inputs.html
[code]
oTable.fnSort([[3, 'asc']]);
oTable.fnSort([[2, 'asc']]);
oTable.fnSort([[1, 'asc']]);
[/code]
Good to hear you've got a workaround, but I'll keep this in mind for future enhancements, particularly if I do a full editable plug-in.
Allan
However, if you edit any of the input text boxes, the search will no longer be accurate.
A workaround to that would be to makesure that column is resorted "onkeyup" of any of the text boxes.
I am currently automatically doing a sort everytime a text field changes... However, this screws up the bStateSave...
Is there a way to update the Datatables store (with new items in the textfields) without the need for sorting?
Currently no - this is a limitation of this feature at the moment, something that I'll be looking at addressing. Really what I think is needed is a plug-in API method that you can call to update the internal data when you find that something has changed externally.
This is the block of code that does the data pull at the moment: https://github.com/DataTables/DataTables/blob/master/media/src/core/core.sort.js#L29 . That should get pulled out into a function and made accessible through a plug-in.
Allan
Really appreciate all the work you've put into what I think is one of the the most useful JS libraries ever!
I made a separate _fnForceDataUpdate / fnForceDataUpdate functions that contain code that Allan mentioned (which is basically the fnSort code, but without actual sorting logic / re-drawing).
This helps to refresh the datastore so you can search on form input fields.
Out of interest, when are you calling it? On 'blur' or 'change' from an input field?
Allan