Sorting on input fields
Sorting on input fields
Hey,
I can't sort on input fields from the search box to the top right corner, but if i click on the column header to filter on the column contain the input fields, then i can also use the search box to search data from the input fields.
How can i solve this? There is one problems searching fields which doesn't contain input fields.
I can't sort on input fields from the search box to the top right corner, but if i click on the column header to filter on the column contain the input fields, then i can also use the search box to search data from the input fields.
How can i solve this? There is one problems searching fields which doesn't contain input fields.
This discussion has been closed.
Replies
Allan
Well yes something like that. Its just that i can't sort on the data with the search box. Only if i choose the particular column as asc or desc sorting. Then i can use the search box to search on that column. I would like that i could use the search on every column no matter if they have been checked for sorting.
Is this possible?
[code]
jQuery.fn.dataTableExt.afnSortData['input'] = function (oSettings, iColumn)
{
var aData = [];
jQuery('td:eq(' + iColumn + ') input', oSettings.oApi._fnGetTrNodes(oSettings)).each(function ()
{
aData.push(this.value);
});
return aData;
}
dataTypes = jQuery(_target + ' th').map(function (pos, th)
{
return { "sSortDataType": jQuery(th).closest('table').find('td:nth-child(' + (pos + 1) + ')').is(':has(input)') ? 'input' : 'html', "bSearchable": true };
});
var oTable = jQuery(_target).dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bSort": true,
"aoColumns": dataTypes,
"bAutoWidth": true,
"sScrollY": sEnableScrollY,
"bScrollCollapse": true,
}
});
[/code]
Allan
Scenario:
In the table below the Column Name contains input textbox. So Peter, Scott and Hanna texts is shown in textboxes.
Table
id Name Address
1 Peter Petersstreet
2 Scott Wallstreet
3 Hanna Montanastreet
When i initialize the datatable with this data and i try to search by "Peter" notthing shows. I can search by "Petersstreet" and it will the correct data.
If i then click on the column header "Name" and then search by "Peter" it will find the correct data.
Does this explain my problem clearer?
The reason it works after sorting is the block of code around line 4205 in the current release - the internal data cache (which is used for filtering) is updated during the sort. However, this doesn't explain why it doesn't work for you just after initialisation - the example I linked to above works in this case (search for "1.7" for example). As far as I can see it should work - it won't if you change the value of the input box - you would need to repeat the sort at that point, and perhaps that is all that is needed? Can you point us to a link where this issue is shown please.
Allan
Sorry i don't have a link for this, but i can tell you that in the link you linked you can't search the "Platform" column in Internet Explorer after initialisation. If you click the "Platform" column to sort by it then you can search for for example "Win". This is somehow the same thing that im having problems with. The difference is that i can't search on any input texts and that is the case no matter if i use chrome or ie.
Or maybe its the way i make the dataTypes for aoColumns. I posted the code above if you wanna have a look.
One of my columns contains input elements. When I use the default Search textbox the values of the input elements are not compared. As suggested by Allan a few postings ago, I added the "dom-text" sorting but even after doing that the search continues to not work.
Any thoughts?
Bascially, when u edit text of an inputfield, lets say I change "Mary" to "Bob" in an input field, immediately if i try to search for "Bob", no results show...
It will only work if i sort that particular columne ONCE. Only then will "Bob" appear.
This is the case here as well:
http://datatables.net/examples/plug-ins/dom_sort.html
If u try editing one of the cells with an input field, and then immediately try to search for that string, it will not appear until u sort that column once.
Any workarounds?
Thanks!! :)