Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
sethumadhavvarma
Posts: 2
Registered: ‎10-29-2013
My Device: z10

How to impliment search option for listview

[ Edited ]

i have listview of countrys i want to impliment search option to easyly select country, 

 

thanks in advance.

Developer
knobtviker
Posts: 145
Registered: ‎05-31-2013
My Device: BlackBerry Z10 Limited Edition

Re: How to impliment search option for listview

Take a look at the Cascade Notebook example. The solution is in there. You use a filter on your model.

 

http://blackberry.github.io/Cascades-Samples/notebook.html

New Contributor
sethumadhavvarma
Posts: 2
Registered: ‎10-29-2013
My Device: z10

Re: How to impliment search option for listview

Thank you.

 

             i am new to cascades. i am using XmlDataModel to add items to listview in that case is there anyway to filter items in listview.

 

Thanks in advance

Developer
knobtviker
Posts: 145
Registered: ‎05-31-2013
My Device: BlackBerry Z10 Limited Edition

Re: How to impliment search option for listview

YAou can use XMLDataAccess to parse your XML, then fill it upo in GroupDataModel  that you can filter, just as in the example provided. :smileyhappy:

New Developer
sharath_moblie
Posts: 104
Registered: ‎09-25-2013
My Device: BB 10

Re: How to impliment search option for listview

I don't know whether it is useful,

 

try this,

 

add this to yourclass.hpp

Q_INVOKABLE void filterDataModel(QString txt);

and in yourclass.cpp

void yourclass::filterDataModel(QString txt)
{
	QStringList* tempList = new QStringList();
	QVariantMap mapTest;
	QVariantList *inx=new QVariantList();
	QList<int> toBeDeletedNodes;
	for(int i = 0; i<entireList->size();i++)
	{
		QString var = entireList->at(i);
		if(var.contains(txt, Qt::CaseInsensitive))
			{tempList->append(var);
			}
	}

	//Deletion

	for(int i = 0; i<primaryDtMdl->size();i++)
	{
		inx->append(i);
		QString var = primaryDtMdl->value(i);
		bool flagTobeDeleted = true;
		 for(int j = 0; j<tempList->length(); j++)
		 {
			 if(tempList->at(j).compare(var)==0)
			 {
				 flagTobeDeleted = false;
				 break;
			 }
		 }

		 if(flagTobeDeleted)
			 {
			   toBeDeletedNodes.append(i);
			 }
	}

	for(int i = 0; i < toBeDeletedNodes.size(); i++)
		{   primaryDtMdl->removeAt(toBeDeletedNodes.value(i) - i);

//		mapTest["key"]= primaryDtMdl->value(i);//lang_text
//				mapTest["lang_text"]=Helper::lang_settings;


		}
	m_dataModelTEST->clear();
	for(int m=0;m<primaryDtMdl->size();m++){

		mapTest["key"]=primaryDtMdl->value(m);
		mapTest["lang_text"]=Helper::lang_settings;
		m_dataModelTEST->insert(mapTest);
		lv->setDataModel(m_dataModelTEST);
	}


	//Append.
	for(int i = 0; i<tempList->length();i++)
		{
		QString var = tempList->at(i);
		 bool flagTobeAppended = true;
		for(int j = 0; j<primaryDtMdl->size(); j++)
				 {
					 if(primaryDtMdl->value(j).compare(var)==0)
					 {
						 flagTobeAppended = false;
						 break;
					 }
				 }
		if(flagTobeAppended)
		  primaryDtMdl->append(var);
		}
	    m_dataModelTEST->clear();
		for(int m=0;m<tempList->length();m++){

			mapTest["key"]=primaryDtMdl->value(m);
			mapTest["lang_text"]=Helper::lang_settings;
			m_dataModelTEST->insert(mapTest);
			lv->setDataModel(m_dataModelTEST);
		}

//Sort
	int n = primaryDtMdl->size();
	for(int i=0;i<n-1;i++)
	{
		for(int j=0;j<n-i;j++)
			{
				if(!(primaryDtMdl->value(j).compare(primaryDtMdl->value(j+1))<0))
					{
						primaryDtMdl->swap(j,j+1);

					}
			}
	}

	m_dataModelTEST->clear();
	for (int m = 0; m < primaryDtMdl->size(); m++) {

		mapTest["key"] = primaryDtMdl->value(m);
		mapTest["lang_text"]=Helper::lang_settings;
		m_dataModelTEST->insert(mapTest);
		lv->setDataModel(m_dataModelTEST);
	}

	delete tempList;

}

 and call this unction from your qml.

 

hoping can solve your problem!!