Programatic CellTable sort in GWT not working - gwt

I'm using the ListDataProvider example here as a guide. The columns are sorting fine as expectd based on the provided comparators. I'm trying to programatically apply a sort as alluded to on this line from the example:
// We know that the data is sorted alphabetically by default.
table.getColumnSortList().push(nameColumn);
What this does, is it makes the cell column appear to be sorted with the carrot sort indicator. However, the underlying data isn't sorted. Is there a way to get the table to actually apply the sort progarmatically. I suppose I could use this in conjunction with actually sorting the data via Collections.sort(), but I'd like to avoid that and do it in one place.

You can apply sorting on a column programatically with little exta code. The following code snippet does that -
When ever u set data to the cellTable you have to initialize the ListHandler as below code does -
cellTable.addColumnSortHandler( createColumnSortHandler() );
private ListHandler<T> createColumnSortHandler()
{
final ListHandler<T> listHandler = new ListHandler<T>(listDataProvider.getList());
listHandler.setComparator( sortColumn, comparator );
return listHandler;
}
And when u want to fire the SortEvent execute the following code snippet -
ColumnSortInfo columnSortInfo = new ColumnSortInfo( sortColumn, sortDirection );
cellTable.getColumnSortList().push( columnSortInfo );
ColumnSortEvent.fire( cellTable, cellTable.getColumnSortList());

you have to call setData on grid again.....

Related

How to delete empty rows from Grid in my Form?

I use to fill my StringEdit a simple displayMethod.
This method selected to see some records from myTable and discard others , this method work well, but, in my Grid I see the empty records-rows(that would be the record discarded).
For to fill my StringEdit I used this dispaly method :
display myEXDTypeString nameFIeld()
{
MYTable mineTable;
myEXDTypeString name;
while select mineTable
where this.FieldtoUse== "Value"
name = this.NameFIeld;
return name;
}
There's a way to delete the empty rows?
In my Grid
I have a Lesf site state , I want to have the right situation:
Thanks all!
Enjoy
If you are just trying to get the Form to not display blank records then it could be as easy as setting a QueryBuildRange on the data source:
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
super();
queryBuildDataSource = this.query().dataSourceName(mineTable_ds.name());
queryBuildRange = queryBuildDataSource.addRange(fieldNum(MineTable, FieldToUse));
queryBuildRange.value('>0');
I solved my problem: the cause is the Form DataSource relation.
OuterJoin Split my Lines.
Thanks all, enjoy!

Form grid filters

I want store the filters entered on the grid, is it possible to store the filters entered on filter pane of the grid.
I want to use those filters entered in my class, please help me in this regard.
No, form queries cannot be saved as code (but such functionality could be programmed).
A form query could be passed from the form to a class, using a parmQueryRun method or similar.
See:
How to Create Queries by using the AOT
How to Create Queries by Using X++
Yes you can retrieve the filters by getting the form's queryRun's query and packing that into a container to be stored/passed/unpacked.
The form has a query, that is passed to QueryRun, then the users puts filters/dynamic joins/etc on that query that belongs to the QueryRun. So you need the modified query to store what you want from it.
void clicked()
{
Query q = salestable_ds.queryRun().query();
int i;
container c;
for (i = 1; i <= q.queryFilterCount(); i++)
{
info(strFmt("%1: %2", q.queryFilter(i).field(), q.queryFilter(i).value()));
}
// If we want to store these we can do
c = q.pack();
}
See this post http://dynamicsuser.net/forums/t/63208.aspx

Remove all columns from a CellTable

I'm using a CellTable from GWT 2.1.0.M3. There are removeColumn functions, but no removeAllColumns or anything. Since "columns" is a private member of CellTable, not even my extension of CellTable can easily access it.
For now, I'm just storing the number of columns I add so I can remember to remove them all. Anyone know a better way?
I am using this way
Take count of columns of table
int count = this.getView().getTbcell().getColumnCount();
Loop through and remove first column
for(int i=0;i<count;i++){
this.getView().getTbcell().removeColumn(0);
}
Thats it we are done :-)
while (cellTable.getColumnCount() > 0) {
cellTable.removeColumn(0);
}
This might not be what your looking for but it works for me:
getCellTable().setVisibleRange(0, 0);
listViewAdapter.updateRowData(0, result);
getCellTable().setVisibleRange(0, 10);

Using linq select to provide a grid datasource, properties are read-only

I am using the return from the following call as the datasource for a grid.
public object GetPropertyDataSourceWithCheckBox( )
{
return (
from p in LocalProperties
join c in GetCities( ) on p.CityID equals c.CityID
orderby p.StreetNumber
select new { Selected = false, p.PropertyID, p.StreetNumber, p.StreetName, c.CityName } ).ToList( );
}
I get a checkbox in the grid, but it is READ-ONLY. [For the record, the grid is DevExpress.] Is there a way around this, short of creating a non-anonymous class?
Continuing research tells me that, in fact, anonymous classes returned by linq are always read-only, so, apparently, creating an actual class is best (only?) solution.

ADO.NET Mapping From SQLDataReader to Domain Object?

I have a very simple mapping function called "BuildEntity" that does the usual boring "left/right" coding required to dump my reader data into my domain object. (shown below) My question is this - If I don't bring back every column in this mapping as is, I get the "System.IndexOutOfRangeException" exception and wanted to know if ado.net had anything to correct this so I don't need to bring back every column with each call into SQL ...
What I'm really looking for is something like "IsValidColumn" so I can keep this 1 mapping function throughout my DataAccess class with all the left/right mappings defined - and have it work even when a sproc doesn't return every column listed ...
Using reader As SqlDataReader = cmd.ExecuteReader()
Dim product As Product
While reader.Read()
product = New Product()
product.ID = Convert.ToInt32(reader("ProductID"))
product.SupplierID = Convert.ToInt32(reader("SupplierID"))
product.CategoryID = Convert.ToInt32(reader("CategoryID"))
product.ProductName = Convert.ToString(reader("ProductName"))
product.QuantityPerUnit = Convert.ToString(reader("QuantityPerUnit"))
product.UnitPrice = Convert.ToDouble(reader("UnitPrice"))
product.UnitsInStock = Convert.ToInt32(reader("UnitsInStock"))
product.UnitsOnOrder = Convert.ToInt32(reader("UnitsOnOrder"))
product.ReorderLevel = Convert.ToInt32(reader("ReorderLevel"))
productList.Add(product)
End While
Also check out this extension method I wrote for use on data commands:
public static void Fill<T>(this IDbCommand cmd,
IList<T> list, Func<IDataReader, T> rowConverter)
{
using (var rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
list.Add(rowConverter(rdr));
}
}
}
You can use it like this:
cmd.Fill(products, r => r.GetProduct());
Where "products" is the IList<Product> you want to populate, and "GetProduct" contains the logic to create a Product instance from a data reader. It won't help with this specific problem of not having all the fields present, but if you're doing a lot of old-fashioned ADO.NET like this it can be quite handy.
Although connection.GetSchema("Tables") does return meta data about the tables in your database, it won't return everything in your sproc if you define any custom columns.
For example, if you throw in some random ad-hoc column like *SELECT ProductName,'Testing' As ProductTestName FROM dbo.Products" you won't see 'ProductTestName' as a column because it's not in the Schema of the Products table. To solve this, and ask for every column available in the returned data, leverage a method on the SqlDataReader object "GetSchemaTable()"
If I add this to the existing code sample you listed in your original question, you will notice just after the reader is declared I add a data table to capture the meta data from the reader itself. Next I loop through this meta data and add each column to another table that I use in the left-right code to check if each column exists.
Updated Source Code
Using reader As SqlDataReader = cmd.ExecuteReader()
Dim table As DataTable = reader.GetSchemaTable()
Dim colNames As New DataTable()
For Each row As DataRow In table.Rows
colNames.Columns.Add(row.ItemArray(0))
Next
Dim product As Product While reader.Read()
product = New Product()
If Not colNames.Columns("ProductID") Is Nothing Then
product.ID = Convert.ToInt32(reader("ProductID"))
End If
product.SupplierID = Convert.ToInt32(reader("SupplierID"))
product.CategoryID = Convert.ToInt32(reader("CategoryID"))
product.ProductName = Convert.ToString(reader("ProductName"))
product.QuantityPerUnit = Convert.ToString(reader("QuantityPerUnit"))
product.UnitPrice = Convert.ToDouble(reader("UnitPrice"))
product.UnitsInStock = Convert.ToInt32(reader("UnitsInStock"))
product.UnitsOnOrder = Convert.ToInt32(reader("UnitsOnOrder"))
product.ReorderLevel = Convert.ToInt32(reader("ReorderLevel"))
productList.Add(product)
End While
This is a hack to be honest, as you should return every column to hydrate your object correctly. But I thought to include this reader method as it would actually grab all the columns, even if they are not defined in your table schema.
This approach to mapping your relational data into your domain model might cause some issues when you get into a lazy loading scenario.
Why not just have each sproc return complete column set, using null, -1, or acceptable values where you don't have the data. Avoids having to catch IndexOutOfRangeException or re-writing everything in LinqToSql.
Use the GetSchemaTable() method to retrieve the metadata of the DataReader. The DataTable that is returned can be used to check if a specific column is present or not.
Why don't you use LinqToSql - everything you need is done automatically. For the sake of being general you can use any other ORM tool for .NET
If you don't want to use an ORM you can also use reflection for things like this (though in this case because ProductID is not named the same on both sides, you couldn't do it in the simplistic fashion demonstrated here):
List Provider in C#
I would call reader.GetOrdinal for each field name before starting the while loop. Unfortunately GetOrdinal throws an IndexOutOfRangeException if the field doesn't exist, so it won't be very performant.
You could probably store the results in a Dictionary<string, int> and use its ContainsKey method to determine if the field was supplied.
I ended up writing my own, but this mapper is pretty good (and simple): https://code.google.com/p/dapper-dot-net/