jQuery UI Widgets › Forums › Grid › Restrict special characters in filter row
Tagged: character, createfilterwidget, Enter, filter, filter row, filtertype, grid, jqxgrid, paste, row, showfilterrow, special
This topic contains 6 replies, has 3 voices, and was last updated by Dimitar 10 years, 2 months ago.
-
Author
-
Hi,
How to restrict entering special characters in filter row of grid.
Thanks,
VijiHello Viji,
Unfortunately, this cannot be achieved. However, please make sure you have set the correct filtertype to each column (“textbox”, “checkedlist”, “checkbox”, “date” or “number”) to avoid entering inappropriate values in the filter row cells.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Were there any jqxGrid updates since this post to implement this functionality?
Hello swagdiar,
This restriction can be implemented using the createfilterwidget callback function, e.g.:
columns: [{ text: 'Name', columntype: 'textbox', filtertype: 'input', datafield: 'name', width: 215, createfilterwidget: function(column, columnElement, widget) { var input = $(widget).find('input').eq(0); input.on('keypress', function(event) { var regex = new RegExp("^[a-zA-Z0-9]+$"); var key = String.fromCharCode(!event.charCode ? event.which : event.charCode); if (!regex.test(key)) { event.preventDefault(); return false; } }); } }, ...For more on this callback, please refer to the columns entry of the jqxGrid API Documentation.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thanks, Dimitar. The issue with that approach is copy&pasting in special characters.
Dimitar, is the “return false” line necessary?
Hi swagdiar,
Actually, you can keep only
return false(more information). As for the copy/paste case, you can bind to the input’s paste event and execute a custom logic similar to the one in the keypress event handler. More information about binding to paste can be found here: http://stackoverflow.com/a/11605419.Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.