-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filter_startsWith and AJAX #526
Comments
Try something like this (demo): $(function () {
var endsWith = false;
$("table")
.tablesorter({
theme: 'blue',
widgets: ['filter'],
widgetOptions: {
filter_startsWith: false,
filter_hideEmpty: false
}
})
.tablesorterPager({
// leave off {filterList:fcol} from ajaxUrl
ajaxUrl: "data?page={page}&size={size}&{sortList:col}",
ajaxProcessing: function (ajax) {
// do something with the ajax
return ['', 0];
},
// modify the url after all processing has been applied
customAjaxUrl: function (table, url) {
var c = table.config,
wo = c.widgetOptions,
sql = {filter:[]},
filters = $(table).data('lastSearch') || [];
$.each(filters, function (i, v) {
v = v || '';
sql.filter[i] = wo.filter_startsWith ? v + '%' :
endsWith ? '%' + v :
v;
});
// send the server the current page
return url + '&' + $.param(sql);
}
});
/* DEMO STUFF */
$('input[type=radio]').on('change', function(){
var c = $('table')[0].config;
c.widgetOptions.filter_startsWith = $('.startsWith').prop('checked');
endsWith = $('.endsWith').prop('checked');
// remove the next line if you don't want the radio
// button to automatically update the ajax url
c.pager.last.page = c.pager.page + 1;
c.$table.trigger('update');
});
}); Basically this is how it is done:
|
Great - looks just what I need..... On 4 March 2014 15:16, Rob G [email protected] wrote:
|
I'm guessing this issue has been resolved, so I'm going to close it. If you continue to have problems, please feel free to continue this discussion. |
Thanks - yes it is and apologies for not closing it On 31 March 2014 22:55, Rob G [email protected] wrote:
|
Is there any way to provide this functionality if using pager and retrieving info with AJAX?
Basically I would like to be able to modify my MySQL search to be one of:
LIKE 'text%'
LIKE '%text'
LIKE '$text%'
depending on a flag the user sets. Of course I can ask the user to type in the search text like that, but is is not very intuitive!
The text was updated successfully, but these errors were encountered: