In my previous project, I've used BeanItemContainer and a Table with GeneratedColumns to simply display a custom component that displays a search result, like google. Title, date, content in a vertical fashion.
As horrible as it was (table) it worked.
Now I want to utilize Grid component for a new project, with the same objective.
The column will be generated and contain a custom component.
Will this work with Grid? is there something better, like a list or repeater component available? Any example of a single column with custom component?
It seems like Vaadin frowns on anything other than simple data or Button renderers.
Update
It looks like adding components don't work out of the box with Grid 7.5+
Also, Grid cells like to be only be fixed hight
ComponentRederer Add-on support cell components, however fix height is still an issue.
Sample code:
public class Result {
String title;
Date date;
URL url;
String description;
List<String> tags;
public Result (){}
}
BeanItemContainer<Result> resultContainer = fetchResults(searchTerm);
I also use a Lazy Container too, beanitem used for simplicity.
I then have a RecordResultComponent that constructs the layout of a single record result in the follow layout:
Title(link with Url)
Date
Description
tag1 tag2 tag3 ...
You can use a Grid alongwith a GeneratedPropertyContainer.
Then, you can use a HtmlRenderer on the custom column.
I hope it helps. :-)
Related
I´m using the SelectItem component with configuration:
private SelectItem nElementsCombo;
nElementsCombo = new SelectItem();
nElementsCombo.setMultiple(true);
nElementsCombo.setMultipleValueSeparator("|");
In the combo the elements selected are shown item_selected_1|item_selected_2|item_selected_3
but when I do:
nElementsCombo.getValueAsString()
Return item_selected_1,item_selected_2,item_selected_3 and I´d like item_selected_1|item_selected_2|item_selected_3
How can I solve this?
from the javadoc :If this item is displaying multiple values, this property will be the string that separates those values for display purposes. Display purpose
I don't catch it, can you replace in your returned string the comma by the pipe ..... !!!
As per Alain's answer, MultipleValueSeparator is only for display purpose.
Means, when you select multiple values from picklist & then when the picklist is hidden on blur (focus lost) of multi select item, the selected values are displayed as a string separated by comma(default). This display can be changed by MultipleValueSeparator. But not the one you get by multiSelectItem.getValueAsString().
Also I don't think, there's any provision in SmartGWT API which fulfills your requirement, as of now.
I need solution for my problem on urgent basis, I am new with mvc, knockout please provide me sample code for my problem. any help will be highly appreciated.
suppose I have an observable array in my viewmodel i.e
var viewmodel = {
vendorproviders : ko.observablearray([])
}
where vendorproviders list consist of multiple attributes like id, name, country, address etc
I want to populate that array in my grid where each row will have a select button, when that button is clicked it should post the id to my controller action either by submitting or by ajax call.
Furthor more that grid should be searchable like if there is a separate text box, based on the value of text box grid should display matching providers else display all providers.
when user search for particular provider grid should populate from observable array instead of making call at server again and again to pupulate the observable array.
I would suggest starting here.
http://learn.knockoutjs.com/#/?tutorial=intro
What you are talking about is all the basic functionality of the tools you referenced.
I have a Telerik grid in my asp.net mvc application that looks something like:
Now it lists all the regions in a zone selected from the list placed just above the grid. zoneid is foreign key in the grid. Now I want that when I add new region in the grid the zoneID should be taken from the list instead of what is present in zone column of the grid because that value is just to display the zone and that can also be removed from the grid as it as apparent from the list which zone the listed regions belong to.
I understand that I could have used editor templates to show this list inside the grid on edit but I prefer it to be outside the grid and provide some filtering on basis of the zone as we are likely to have many regions per zone. so my concern here, now, is how can I set ZoneID of a region (edited or newly added) equal to selected value of list that shows just above the grid control.
When you click on the AddNewRecord button, why don't you set the Value of your zone equals to the zoneId selected in the combobox value ?
I've done something a little similar, but I had to get the value from a Treeview.
private void btnAddContact_Click(object sender, EventArgs e)
{
Int64 companyId = Int64.Parse(treeCompany.SelectedNode.Name);
dsSociete.ContactRow newContact = dsSociete.Contact.NewContactRow();
newContact.SocieteId = societeId;
dsSociete.Contact.AddContactRow(newContact);
}
And once i add a new Contact, it gets automatically its Company (Societe is Company in French) set.
I did it in Winform, but I guess you can do the same in Web?
I solved this problem by hooking the onSave event of Telerik grid like
<%
Html.Telerkik.Grid<xyz.company>()
.Name("name")
.// other properties
.Events(even=>even.onSave("onSave")
.Render();%>
Inside onSave event handler in JS I have written something like
function onSave(e)
{
var data = e.values;
data["companyID"] = $("#CompanySelectList").val();
e.values = data;
return true;
}
onSave event adds the companyID at companyID index of json that will be submitted to the server and modelbinder will bind it with concerning property name of model.
I would like display text and an image in a Silverlight 3 datagrid (i.e. First name, last name, picture). There were many examples on the web utilizing DataTemplate and RowDetailsTemplate in XAML. However, I need to do this all through C# code. Any examples would be highly appreciated.
Thanks,
Sam
Sam,
Steps I'd take:
On your datagrid, set AutoGenerateColumns = false;
Create the columns for text columns and add them to datagrid.Columns
Create a DataTemplateColumn
Assign the DataTemplateColumn .CellTemplate property to the results of a method that looks something like this:
public DataTemplate Create()
{
return (DataTemplate)XamlReader.Load(
#"<DataTemplate
xmlns=""http://schemas.microsoft.com/client/2007"">
<Image Source=""{Binding <your field here>}""/>
</DataTemplate>"
);
}
Bind your grid to your datasource.
That should do it.
My List<BusinessObject> has some public properties that I want to bind to columns in a DataGrid. Unfortunately, the names of the public properties are not good and I may not even know what they are until runtime. For this reason, I set AutoGenerateColumns=True and interecept each DataGridAutoGeneratingColumnEvent so I can inspect what it is and either cancel it, hide it, or name the header something else.
It works great but I cannot figure out how to set the Mode=TwoWay so that my INotifyPropertyChanged events get fired once all the columns are generated and somebody edits a cell.
Bonus question:
On navigating up and down the rows of the grid, does the grid's datacontext automatically get set with that row's BusinessObject?
Thanks to this post, I learned that the binding happens on DataGridTextColumn. So the way to set the Mode at runtime is:
1 private void DataGrid1_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
2 {
3 DataGridTextColumn tc = (DataGridTextColumn)e.Column;
4 tc.Header = "Custom Header";
5 tc.Binding.Mode = BindingMode.TwoWay;
6 }
Now that I have TwoWay binding, I have to figure out how changes make it back to my BusinessObject.
If the binding is correct your business objects will automatically receive the required updates. To do you binding programmatically you might need a little more code, something like:
...
Binding binding = new Binding("Propertyname");
tc.binding.Mode = BindingMode.TwoWay;
...