ramanathansj / salesforce-lightning-datatable

Simple Datatable which takes SOQL query and creates native lightning datatables
Apache License 2.0
22 stars 8 forks source link

SearchBar Component not working with helper #2

Open riazsfclouds opened 7 years ago

riazsfclouds commented 7 years ago

I created one Component Name : SearchBar

SearchBarController.js ({ searchKeyChange: function(component, event, helper) { var myEvent = $A.get("e.c:SearchKeyChange"); myEvent.setParams({"searchKey": event.target.value}); myEvent.fire(); } }) SearchKeyChange.evt In your DataTableV2 Component i register that handler and also added the Component Now i Added DataTableV2Controller.js searchKeyChange: function(component, event) { var searchKey = event.getParam("searchKey"); var action = helper.queryRows(cmp); action.setParams({ "searchKey": searchKey }); action.setCallback(this, function(a) { component.set("v.page", a.getReturnValue()); }); $A.enqueueAction(action); }, Can you please help on this , i stucked on it.
ramanathansj commented 7 years ago

you can debug your searchKey components is getting set correctly or not, i suspect this will work "event.target.value" for html events only not for any lightning button etc.

Also add helper to this method and you don't need to queue it again, since it already does it for you, all your doing is modifying wherecaluse for the query, that's what search is doing (similar to init logic)

searchKeyChange: function(component, event, helper) { var searchKey = event.getParam("searchKey"); //note this wherecaluse you need modify it again to match against field you want to set like match against fields and then set it. //sample code to search on name field var whereClause = component.get("v.whereclause"); if (whereClause) { whereClause = whereClause + 'AND NAME LIKE %'+searchKey+'%' } else { whereClause = 'NAME LIKE %'+searchKey+'%' } component.set("v.whereclause", whereClause); helper.queryRows(component, component.get("v.page") || 0, helper.getSortOrder(component, false)); },

ramanathansj commented 7 years ago

Also debug your final soql and how its getting formatted.

riazsfclouds commented 7 years ago

Hi Ram , Thanks for the Update and i did some changes and you can see i am getting the component set and query is also passigng the values you can see in the Image

image

I modified the DataTableV2Controller.js (as suggested by you ) searchKeyChange: function(component, event,helper) { var searchKey = event.getParam("searchKey"); alert('-----yyyyy---'+searchKey); var whereClause = component.get("v.whereclause"); if (whereClause) { whereClause = whereClause + 'AND NAME LIKE %'+searchKey+'%' } else { whereClause = 'NAME LIKE %'+searchKey+'%' } component.set("v.whereclause", whereClause); alert('-----xxxx---'+whereClause); var action = helper.queryRows(component, component.get("v.page") || 0, helper.getSortOrder(component, false)); },

Do i also have to change the SearchBarController.js ({ searchKeyChange: function(component, event, helper) { var myEvent = $A.get("e.c:SearchKeyChange"); myEvent.setParams({"searchKey": event.target.value}); myEvent.fire(); } })

Need you help in twiking this

Thanks for the help

riazsfclouds commented 7 years ago

Hi @ramanathansj Did you got any chance to have a look into this