jquery - Primefaces - custom component for live filtering in dataTable -


primefaces has done filter p:datatable. great ux site, because filter field in column header, there's no doubt filtering, , it's working live - data changes type (well, if make short pause, it's in opinion user expects).

now i'd place custom in header act filter. so, idea place component in header facet:

<p:column ...>   <f:facet name="header">      <some:mycomponent onkeydown="filteraction()"/>   </f:facet> </p:column> 

the problem filteraction must not update whole datatable component (because component user typing in re-created), must update table body.

i've thought can primefaces selectors (based on jquery selectors), according topic how update data rows using selector datatable? not possible. , datatable.js contains specialized ajax call achieve (line: 839 in primefaces 3.5, release):

    options.onsuccess = function(responsexml) {         var xmldoc = $(responsexml.documentelement),         updates = xmldoc.find("update");         ....         $this.tbody.html(content); 

my question is, possible use such individual filter component, refresh table body, standard filter does, without going deep pf internals , writing specialized ajax handler that?

of course, it's possible make filter outside datatable, ux reduced (the people using application current design much).

it possible put component in column header using facet. however, not possible request datatable body refresh. solution is, send normal request, take on response , handle in custom code part.

if create remotecommand that:

<p:remotecommand id="refreshdatatable" name="refreshdatatable"                actionlistener="#{cartable.dofilter}"                 update="datatable" /> 

the id of command sent server. knowing that, can prepare custom ajax request:

 var options = {         source: 'main:tabview:refreshdatatable',         update: carstable.id,         formid: carstable.cfg.formid } options.onsuccess = customhandler primefaces.ajax.ajaxrequest(options); 

where customhandler code looks that:

var xml = $(resp.documentelement) updates = xml.find('update') for(var i=0; < updates.length; i++) { var update = updates.eq(i), id = update.attr('id'), content = update.text(); if(id == carstable.id){    var tbody = $(content).find('tbody')    carstable.tbody.html(tbody.html()); } else {    primefaces.ajax.ajaxutils.updateelement.call(this, id, content); } primefaces.ajax.ajaxutils.handleresponse.call(this, xml); var paginator = carstable.getpaginator(); if(paginator) {     paginator.settotalrecords(this.args.totalrecords); } if(carstables.cfg.scrollable) {     carstable.alignscrollbody(); } return true; 

we need set in variable totalrecords in java code:

    requestcontext context = requestcontext.getcurrentinstance();       context.addcallbackparam("totalrecords", filteredcars.size());   

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -