jsf - Allow only digits to the filtered textbox (search filter) of dataTable in Primefaces -
is possible apply such validation filtered textbox provided datatable
of primefaces customizing it.
the maximum number of characters textbox can hold can set using filtermaxlength="45"
property of <p:column>
. example.
<p:column headertext="headertext" sortby="#{obj.properyname}" filtermaxlength="45" filterby="#{obj.properyname}"> <h:outputtext value="#{obj.properyname}" /> </p:column>
i can't see such property perform other kind of validations such allowing specific characters, perhaps using regex.
anyway, need allow have digits, since there id
column of type bigint
(primary key, auto-increment) in mysql database mapped long
datatype in entity classes.
is supported primefaces or there way customize it?
afaik primefaces doesn't has option. can use javascript solve that.
you have set id column want limit, input(use filter) have default id filter
, process keydown event
allow digits. example, create 1 form(id="form"
), , nest 1 datatable(id="cars"
),one column(id="cl2"
) , input's id filter
, bind keydown event
filter key user type:
<h:form id="form"> <script type="text/javascript"> //<![cdata[ $(document).ready(function() { $("#form\\:cars\\:cl2\\:filter").keydown(function(event) { // allow: backspace, delete, tab, escape, , enter if ( event.keycode == 46 || event.keycode == 8 || event.keycode == 9 || event.keycode == 27 || event.keycode == 13 || // allow: ctrl+a (event.keycode == 65 && event.ctrlkey === true) || // allow: home, end, left, right (event.keycode >= 35 && event.keycode <= 39)) { // let happen, don't return; } else { // ensure number , stop keypress if (event.shiftkey || (event.keycode < 48 || event.keycode > 57) && (event.keycode < 96 || event.keycode > 105 )) { event.preventdefault(); } } }); }); //]]> </script> <p:datatable id="cars"> <p:column id="cl2" headertext="manufac" filtermatchmode="contains" filterby="#{carr.manufacturer}"> </p:datatable>
see also: how allow numeric (0-9) in html inputbox using jquery?
Comments
Post a Comment