I have a form with text field elements to display data in table view and search field and button.
Data provider is not assigned at design time.
I want to create datasource and assign dataprovider to text field programmatically and diplay data in table view
How to display data when any search is entered and hit button.Do I need to again create datasource for my existing form
Please suggest.
Hi Hardina09.
You can create your data soource from a dataSet with: _dataSet.createDataSource(‘myDataSource’). Then using solutionModel you can attach that dataSource to your form and set the dataProviders to the elements as well.
var _dataSet=databaseManager.getDataSetByQuery('MyServer','SQL_Sentence',MyArgsArray,-1);
var _dataSource=_dataSet.createDataSource('MyDataSource');
var _myForm=solutionModel.newForm('MyNewFormName', _dataSource, 'MyStyleName', false, 500,500);
_myForm.extendsForm='ExistingFormName';
// Following must be done with all the fields that you need
var _Field1=_myForms.getField('Field1');
_Field1.dataProvider='NameOfDataProvider';
forms['MyNewFormName'].controller.show();
I think that your ExistingFormName have the button and text fields to do the search. Searching code should be something like:
function cmdSearch_onAction(event){
if(foundset.find()){
foundset['Field_I_Want_To_Search_On'] = FormVarWhereTheUserEntersSearchString;
foundset.search();
}
}
It is not a big example but I guess will help you. Just dig in
Thanks Juan,
Thank you for reply.
I created form and added above code but different way I am not extending form rather using Main form with sub form which load data using code which you have given in this forum and Main form has search fields.
When form gets loaded in browser it executes above code in onShow() method of subform. Thats working fine
But for searching code in Main Form when I execute below code it throws error : TypeError: Cannot set property “dataSource” of to “mem:MyDataSource”
function onSearch()
{
var sql= '<some sql query>'
ds=databaseManager.getDataSetByQuery('servername',sql,null,1000)
var dataSource=ds.createDataSource('MyDataSource') //TypeError: Cannot set property "dataSource" of to "mem:MyDataSource"
var myForm=solutionModel.getForm('subformName')
myForm.dataSource=dataSource;
forms['subformName'].controller.recreateUI()
}
Any idea why it is throwing error TypeError: Cannot set property “dataSource” of to “mem:MyDataSource”