cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Search item in list using textbox

gajapriya
6-Contributor

Search item in list using textbox

I have placed textbox on top of list widget.I want to search item using text box in list widget.what serivce to write for searching items on textchanged event

1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

 

I've done this with Text field widget (ptcs-textfield):

1.  I have a list with the names of the Things on the platform using Generic Thing template

2. Create new thing with a service (search_text) that is querying the things

var fieldArray = [];
var txt1=txt+"%";   //txt is the input for the service - actually what you are typing in the widget
var queryField = new Object();
var query = new Object();
if(txt1)
{
queryField.fieldName = "name";
queryField.type = "Like";
queryField.value = txt1;

fieldArray.push(queryField);
}


if( fieldArray.length > 1 )
{

query.filters = new Object();
query.filters.type = "AND";
query.filters.filters = fieldArray;

}
else
{

query.filters = fieldArray[0];
}

var params = {
maxItems: 9999 /* NUMBER */,
query: query /* QUERY */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
};


// result: INFOTABLE dataShape: "RootEntityList"
var result = ThingTemplates["GenericThing"].QueryImplementingThings(params);

 

I have used 'Like' query with service QueryImplementingThings service.

3. In the mashup, create the bindings: txt from search_text bind with Text of textfield, Changed event of textfield bind with search_text service, All Data of search_text bind with  List data.

raluca_edu_0-1584981785915.png

 

And done, when typing something in the textfield, you will get data in the list; you can adjust the query per your requirement.

 

* with the widget textbox , you need to hit Enter after typing to get data in the list, so I have used in above example ptcs-textfield widget.

 

Hope it helps,

Raluca Edu

 

 

View solution in original post

2 REPLIES 2

Hi,

 

I've done this with Text field widget (ptcs-textfield):

1.  I have a list with the names of the Things on the platform using Generic Thing template

2. Create new thing with a service (search_text) that is querying the things

var fieldArray = [];
var txt1=txt+"%";   //txt is the input for the service - actually what you are typing in the widget
var queryField = new Object();
var query = new Object();
if(txt1)
{
queryField.fieldName = "name";
queryField.type = "Like";
queryField.value = txt1;

fieldArray.push(queryField);
}


if( fieldArray.length > 1 )
{

query.filters = new Object();
query.filters.type = "AND";
query.filters.filters = fieldArray;

}
else
{

query.filters = fieldArray[0];
}

var params = {
maxItems: 9999 /* NUMBER */,
query: query /* QUERY */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
};


// result: INFOTABLE dataShape: "RootEntityList"
var result = ThingTemplates["GenericThing"].QueryImplementingThings(params);

 

I have used 'Like' query with service QueryImplementingThings service.

3. In the mashup, create the bindings: txt from search_text bind with Text of textfield, Changed event of textfield bind with search_text service, All Data of search_text bind with  List data.

raluca_edu_0-1584981785915.png

 

And done, when typing something in the textfield, you will get data in the list; you can adjust the query per your requirement.

 

* with the widget textbox , you need to hit Enter after typing to get data in the list, so I have used in above example ptcs-textfield widget.

 

Hope it helps,

Raluca Edu

 

 

slangley
23-Emerald II
(To:gajapriya)

Hi @gajapriya.

 

If the previous response answered your question, please mark it as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon

Top Tags