In addition to built-in client services, you can also programmatically create your own datasource entirely in the client-side, then bind it to the WebCombo via client API. This mode is called ClientDataSource.
This topic shows how to bind WebCombo to client-side Data Source.
To bind WebCombo to Client-side Data Source
- Right-click on WebCombo control and select Properties.
- Expand ClientBindingSettings and set DataSourceType property to ClientDataSource.
- Create a function called CreateData(). In the function, there are several things that need to be configured.
- First of all, create a DataTable using the following code:
Javascript Copy Code var combo = ISGetObject("wcClient"); var dataTable = new ISDataTable(); var idColumn = new ISDataColumn(dataTable); var textColumn = new ISDataColumn(dataTable); var checkColumn = new ISDataColumn(dataTable); var descColumn = new ISDataColumn(dataTable);
- Then, set up the data columns like following:
Javascript Copy Code /* setup data columns */ DataTable.Name = dataTable.TableName = "Root"; idColumn.Name = idColumn.ColumnName = "ID"; textColumn.Name = textColumn.ColumnName = "Text"; checkColumn.Name = checkColumn.ColumnName = "Bool"; descColumn.Name = descColumn.ColumnName = "Desc";
- Next, add the created columns to the data table:
Javascript Copy Code /* add columns to data table */ dataTable.Columns.Add(idColumn); dataTable.Columns.Add(textColumn); dataTable.Columns.Add(checkColumn); dataTable.Columns.Add(descColumn);
- The columns has been set. Now, add rows to the data table like following:
Javascript Copy Code /* add rows to data table */ for (var i = 0; i < 100; i++) { var dataRow = dataTable.NewRow(); dataRow.Cells.GetNamedItem("ID").Value = i; dataRow.Cells.GetNamedItem("Text").Value = "Item " + i; dataRow.Cells.GetNamedItem("Bool").Value = (i % 3 != 0); DataRow.Cells.GetNamedItem("Desc").Value = "Description " + i; dataTable.Rows.Add(dataRow); }
- Everything has been configured. Finally, bind the data table to WebCombo.
Javascript Copy Code /* bind the data table to WebCombo */ combo.SetDataSource(dataTable); combo.DataBind(); combo.Render(); combo.ShowDropDown(); event.cancelBubble = true; event.returnValue = false;
- The CreateData() function has been completed. You can invoke this function using any control, such as using HTML Input Button's OnClick event.
Javascript Copy Code function CreateData() { var combo = ISGetObject("wcClient"); var dataTable = new ISDataTable(); var idColumn = new ISDataColumn(dataTable); var textColumn = new ISDataColumn(dataTable); var checkColumn = new ISDataColumn(dataTable); var descColumn = new ISDataColumn(dataTable); /* setup data columns */ DataTable.Name = dataTable.TableName = "Root"; idColumn.Name = idColumn.ColumnName = "ID"; textColumn.Name = textColumn.ColumnName = "Text"; checkColumn.Name = checkColumn.ColumnName = "Bool"; descColumn.Name = descColumn.ColumnName = "Desc"; /* add columns to data table */ dataTable.Columns.Add(idColumn); dataTable.Columns.Add(textColumn); dataTable.Columns.Add(checkColumn); dataTable.Columns.Add(descColumn); /* add rows to data table */ for (var i = 0; i < 100; i++) { var dataRow = dataTable.NewRow(); dataRow.Cells.GetNamedItem("ID").Value = i; dataRow.Cells.GetNamedItem("Text").Value = "Item " + i; dataRow.Cells.GetNamedItem("Bool").Value = (i % 3 != 0); DataRow.Cells.GetNamedItem("Desc").Value = "Description " + i; dataTable.Rows.Add(dataRow); } /* bind the data table to WebCombo */ combo.SetDataSource(dataTable); combo.DataBind(); combo.Render(); combo.ShowDropDown(); event.cancelBubble = true; event.returnValue = false; }
Concepts
Client Binding API