ZK listbox sort multiple columns - listbox

Under normal conditions no huge data or paging even, how can you sort a ZK listbox by using more than one column ?
Sort by the first column, sort by the second and so on.
And defenetely how do you keep the sorted icon on label of header intact unless you click it again ?
I have a ZK version 7.0.3 for reference.

Use MVVM and do the actual sorting in the view model. In the view model have a custom comparator which sorts on multiple fields. Your sortable listbox listheaders would look something like this:
<listheader label="Name" sort="auto(each.name)" onSort="#command('nameSort', asc=event.isAscending())" />
and in your view model:
#Command
#NotifyChange("names")
public void nameSort(#BindingParam("asc") final boolean isAscending) {
// modify your custom comparator
}
As an aside, if you don't have big data and aren't using paging do you really need to sort on multiple fields?

It can even be easier because auto sort also supports multiple fields also.
sort="auto(lastName, firstName)"
Like this, no extra code needed for the header icon.

Related

Columns order in ListGrid Smartgwt

How can I programmatically change the order of columns in ListGrid? I have search for an appropriate method in javadoc but found nothing. Is it possible?
Check out setViewState method and this example that saves and restores grid preferences (including column order). So in short, you are interested in getting viewState string from ListGrid data and using it. Remember to redraw grid after setting new viewState.

MVC selectable GridView

I am designing a webpage using MVC. One of the pages has the following controls and functions:
Controls:
2 GridViews (gvItems, gvSelectedItems)
3 buttons (btnTransferSingle, btnTransferAll, submit)
Functions
gvItems will be populated with a set of items that contains: Name, points
gvSelectedItems will contain items that is transferred from gvItems. Hence it will also contain: Name, points
both GirdViews supports multiple selection
btnTransferSingle will transfer all selected items from gvItems to gvSelectedItems.
btnTransferAll will transfer all remaining items from gvItems to gvSelectedItems.
btnSubmit will send all the items from gvSelectedItems to the Controller.
I am not sure how to the following:
1) How to create a gridview that supports multiselection and displaying of multiple model attribute.
2) How to transfer the items from one gridview (gvItems) to another (gvSelectedItems)?
3) How to pass back all the items from gvSelectedItems to the controller?
I am able to do the stuff that was mentioned using listBox but listBox only allows displaying of only one attribute and doesn't have a header.
I used Matt Kruse Javascript's Toolbox to aid the moving of items between listboxes.
Any help is appreciated. Thanks.
I think that listboxes are the correct approach here.
If you want to display both attributes try to concatenate them when loading the data.
Headers can be somewhat added with html/css

Are there data grid components in JSF/PrimeFaces?

I need an iterating component like a <h:datatable> which generates <div> elements on every iteration and adds pagination. Something like an <ui:repeat> with pagination.
Does it exist in PrimeFaces or any other library?
I think the p:dataTable element in PrimeFaces does what you want. It draws a pagination panel with first/prior/next/last control semantics. Here is the example for pagination.
What I recommend most is their "lazy data table loading" mode where you do not transfer any data from the server to the client that is not actually going to be displayed. In this way you can handle a data source with millions of records. Here is the example for lazy data loading.
If you want a grid and not a table, I think the PrimeFaces p:dataGrid implementation is the best in the business. Unfortunately my own application doesn't use it, but the example is here.

Add calculated column with checkboxes to datagrid

In my application I have a TcxGrid (devexpress datagrid) that displays the data returned from a stored procedure.
Now I would like to add a column showing checkboxes from which the values cannot come from the database but are calculated internally.
When the checkboxes are clicked, some internal logic needs to be triggered.
Any suggestions?
#boris, I recommend you use the Support Center site of DevExpress for this type of question, there are thousands of articles to DevExpress products.
Anyway I leave here a link to something that might help ;)
How to set up an unbound item in a data-aware View
Are you creating the view at runtime or at designtime?
I sort of cheated when I did this at runtime, and returned a static value as one column from my query:
select false as processed,col1,col2 from table where true
I could then safely attach the dataset, and I had my new column to play with.
You would then perhaps use the properties.onChange or properties.onEditValueChanged for your logic code.

Showing many tables in many dropdown lists. c#, asp.net-mvc, linq2sql

I want to use an example to explain what I want.
Assume I've following DB design:
Item (id, name, categoryID);
Category (id, name);
When user wants to create an Item (fill in form), I'll give a list of categories in a dropdownlist, and when user chooses one of the categories ASP.NET MVC will automatically bind categoryID, to the selected one. I need to present same dropdown list when editing the item with correct selected one.
Question:
But my DB is very big, and it requires around 30-40 (maybe even more) category-like tables, that contain just "id" and "name", and all tables need to be shown in dropdown list while creating some other object, and also needs to be presented while editing the object. Definitely above schema doesn't work, because it's tedious to write same logic 100 times with just different table names. (I'm using Linq2SQL)
Currently my solution is:
Make a view that's based in all such tables and in application I just call a function that construction dropdownlist from that single view. But it's still tedious to change view definition everytime I add a new table.
Do you guys think of a better solution for this tedious work, possibly using reflection or some other tecnologies.
It is not a problem "Definitely above schema doesn't work, because it's tedious to write same logic 100 times with just different table names."
If I were you, I will mark an addition interface on these class using "partial class" feature.
Then, I will write few extension method for the partial class.
If anyone interested in the solution:
I've used reflection to solve this problem.
I use reflection over DataContext to get the Table (by string name), and get its fields and construct the optionlist.

Resources