Table converter integer to image - vaadin

I am fairly new to Vaadin and am creating a small application. Here I display a table with some columns. In one of the columns I have an integer which, depending on its value, I wish to show an image in that cell.
I have been looking onto table converters but have not find what I am looking for. Could someone help me on the road to get this to work?
Thanks!

You can accomplish this using a column generator.
table.addGeneratedColumn("imageNr", new Table.ColumnGenerator() {
#Override
public Object generateCell(Table source, Object itemId, Object columnId) {
Integer i = (Integer) source.getItem(itemId).getItemProperty("imageNr").getValue();
Resource res = getImageResource(i); // get the resource depending the integer value
return new Image(null, res);
}
});
The column id "imageNr" on the first line doesn't have to be the same as the item property id, but if it is it replaces the integer column in the table and also makes this column sortable according to the underlying integer value.

Related

How to sort on hidden or data-attribute value in textSorter

I have a "name" column in a table that contains a persons full name (ie. first+last name). The objective is to sort the column based on the person's last name first, then first name. My initial naive approach for the textsorter function was
function (a, b){
const aSplit = a.split(' ');
const bSplit = b.split(' ');
const aReverse = aSplit[1] + aSplit[0];
const bReverse = bSplit[1] + bSplit[0];
return aReverse.localeCompare(bReverse);
}
Unfortunately, some of the names I have to sort have extraneous spaces in them, potentially in either the first name or last name field. So I have to support this in my sorting.
I am currently only using the combined first+last name string for display and sorting but I have access to the seperate name strings as well as a preformatted lastname, firstname version. I'd like to attach either of these to the <th> tags as a data attribute or something like that and sort using that instead of the actual value but I'm not sure how to go about accessing those attributes from within the textsorter function.
Maybe try this - when you build the table HTML, add the last name + first name into a data-text attribute of the cell. Tablesorter will automatically use that attribute over the actual text within the cell. See textAttribute option to allow changing that attribute name.

Convert a Dart Row Object to a Map. (sqlJocky)

I'd like to get the row data given to me by sqlJocky in my Dart Server application and convert it (with column names) to a Map. Ie. row['email'] == "somename".
The row data is a "_BinaryDataPacket" which is an extension of Row type. Right now the method recommended by the sqlJocky developer to access the data involves either knowing the column name of what your accessing in the database:
row.email == "somename"
or just ignoring the column name all together:
row[0] == "somename"
I've tried a few hacks to get at the column data and even edited the original sqlJockey code to get at _BinaryDataPacket._fieldIndex to made it public. While that did give me access to Symbol instances of the Column titles to build a map with, I would like to avoid modifying the developers stable code if at all possible.
I assume there has to be an easy way to get the column names and put them in a Map with the row data.
TLDR:
I want to Convert alpha.brava == "charle" into alpha["bravo"] == "charle".
Thanks
In your results, you have a fields list attribute.
So you could do this :
.then((Results results) {
results.forEach((Row row) {
Map r = new Map();
for(int i=0; i<results.fields.length; i++) {
r[results.fields[i].name] = row[i];
}
});
});
This will map the data from a row to the map

Confused about DropDownListFor

I am retrieving a few bunches of int/string pairs that I want to generate dropdown lists for, and subsequently use these filter a collection of items.
Currently, I create these filters as SelectLists in the Controller this way:
foreach (int key in filterChoices.Keys)
subFilter.Add(new SelectListItem {Value = key.ToString(), Text = filterChoices[key]});
where "filterChoices" holds the id (int) and text (string) as key, value pairs.
Then I'm a bit confused as to what to do. I have tried to put together bits and pieces from various examples, but don't really understand what's going on.
This is what I'm trying currently:
Html.DropDownListFor(m => m.SelectedDimension, new SelectList(Model.DimensionFilter, "Text", "Value", Model.DimensionFilter.First().Text));
The first part, I'm not really sure what its use is, but I am assuming it's the property whose change controls what is being selected in the list? Something along those lines? So I'm trying to set this int to some arbitrary value that corresponds to one filter entry, but to no avail.
No DropDown shows up.
just use
#Html.DropDownListFor(m => m.SelectedDimension, Model.DimensionFilter)
if you already created a selectList

Vaadin table rows

I'm using vaadin for UI,I have a entity class which has #OneToMany relationship, so Entity class has a list. so I want to display those values in a vaadin table,Could anyone explain me how to do that? Thank you, here is my class details
#OneToMany
private List<Driver> driverList = new ArrayList<Driver>()
This field in TempLocation class.
so when I query from the data I get one city and list of drivers. In vaadin table I could display query result in a single row(assume I have only one record in a database with more than one Driver)
Lets say my table has two columns "Location" and "Driver", so I want to display the results in multiple rows,I want to go through the List and take one drive at time display along with the City
Currently how it display in the table.
|Driver_______________| Location | (Table head)
[Driver1,Driver2,Driver3] | Kolonnanwa (row)
I want display this
|Driver______________| Location | (Table head)
Driver1______________|Kolonnawa (row 1)
Driver2______________| Kolonnawa (row 2)
Driver3______________| Kolonnanwa (row 3)
"_" used to display spaces ,
Hope you got what I want to express and can anyone tell me how to do this?
Thankxx in Advance
Thank you,
Cheers
If you only want a different way of filling the table , I recommend just iterating over the List of your drivers and create one row for everyone (assuming every driver knows his city)
Check this example:
/* Create the table with a caption. */
Table table = new Table("This is my Table");
/* Define the names and data types of columns.
* The "default value" parameter is meaningless here. */
table.addContainerProperty("Driver", String.class, null);
table.addContainerProperty("City", String.class, null);
/* Add a few items in the table. */
int i = 1;
for(Driver driver : driverslist){
table.addItem(new Object[] {
driver.getName(),driver.getCity(), new Integer(i));
i++
}
The Integer in the addItem()-method is for the rownumber.
Please check the articles given in the vaadin book about the use of the table component.

How can I Alias Data in a WebGrid

I have an existing database that I can't change. I have a column of type int that has various numbers that mean something.
This something would be a string. For example, 1="dog", 2="cat", 3="bird". There are a dozen or so integers to deal with.
I'm using ASP.NET MVC 3 with EF 4.1 and have a WebGrid binding to the Model. Is there a way to alias the data for these integers listed in the WebGrid to display the string value that mean something to the user?
Any help on this would be greatly appreciated!
Add an enum to your Model:
public enum foo
{
dog = 1, cat, bird //etc
}
Hopefully, you are using ViewModels. If you are, add a property for the enum:
public foo thing {get;set;}
And set the value of thing based on the integer value you get from the database:
Model m = new Model{number = 3};
m.thing = (foo) m.number;
Or you could create a helper and use that within the format parameter to set a value based on the integer, or you could use JavaScript/jQuery to alter the values from ints to strings once they have been rendered to the browser.

Resources