Hi all,
Today I am writing this post to tell you guys how you can implement Search functionality on a field of a form.
I have taken ProjTable form in AOT and customized it.
You can see a string field on the top of this form with Label : "Search Name".The text typed in this field is used to filter data in the "Name" column of this form.
So, Let's begin by adding a string edit control in the header of this form.
In the class declaration method of this form add the following code:
QueryBuildRange nameRange;
Name nameFilter;
I have declared a QuerybuildRange variable which I would be adding a range in the 'init' method of the datasource(ProjTable).
Now, we will override 3 methods of the StringEdit control on the form.
1) 'enter' method:
public void enter()
{
super();
this.setSelection(strlen(this.text()),strlen(this.text()));
}
It just selects the text written in the text field.
2) 'modified' method:
public boolean modified()
{
boolean ret;
ret = super();
nameFilter = '*'+this.text()+'*';
projtable_ds.executeQuery();
return ret;
}
Execute the datasource query and store the field text in a variable(nameFilter).
3) 'textChange' method:
public void textChange()
{
super();
this.modified();
}
Just call the modified method every time the text changes.
Final step is to override the 'executequery' method of the datasource and provide a value to the range on 'Name' column.
void executeQuery()
{
nameRange.value(nameFilter);
super();
}
It will work like this..
That's it.
Happy Daxing :)
Today I am writing this post to tell you guys how you can implement Search functionality on a field of a form.
I have taken ProjTable form in AOT and customized it.
You can see a string field on the top of this form with Label : "Search Name".The text typed in this field is used to filter data in the "Name" column of this form.
So, Let's begin by adding a string edit control in the header of this form.
In the class declaration method of this form add the following code:
QueryBuildRange nameRange;
Name nameFilter;
I have declared a QuerybuildRange variable which I would be adding a range in the 'init' method of the datasource(ProjTable).
1) 'enter' method:
public void enter()
{
super();
this.setSelection(strlen(this.text()),strlen(this.text()));
}
It just selects the text written in the text field.
2) 'modified' method:
public boolean modified()
{
boolean ret;
ret = super();
nameFilter = '*'+this.text()+'*';
projtable_ds.executeQuery();
return ret;
}
Execute the datasource query and store the field text in a variable(nameFilter).
3) 'textChange' method:
public void textChange()
{
super();
this.modified();
}
Just call the modified method every time the text changes.
Final step is to override the 'executequery' method of the datasource and provide a value to the range on 'Name' column.
void executeQuery()
{
nameRange.value(nameFilter);
super();
}
It will work like this..
That's it.
Happy Daxing :)