You need to sign in to do that
Don't have an account?
Atroxy
Permanent Sort for pageBlockTable
Heya,
I've got a VF pageBlockTable, where I can add my products to my opportunity. The VF shows the products in the order I added them to the pricebook. Is there anyway I can change that. Either sort by column X (alphabetically) or even better sort by colum X defining the order myself. E.g. Sort by Column X in Oder: Dog, Cat, Bird, Mouse.
I'm unsure where to look for a solution, does this go in the controller or my apex code?
Greetings!
In your Apex Code, you could add an ORDER BY clause to your SOQL, or you could sort() the list (default sorting), or you could even write a custom sort function (via a "wrapper" class and implementing the Comparable interface). It all depends on exactly what you're seeking to do, but should be possible.
All Answers
In your Apex Code, you could add an ORDER BY clause to your SOQL, or you could sort() the list (default sorting), or you could even write a custom sort function (via a "wrapper" class and implementing the Comparable interface). It all depends on exactly what you're seeking to do, but should be possible.
I'll use ORDER BY for now, and created a new product field, which assigns a letter to ease sorting. In case anyone has an idea how to do the sorting and defining the order in the code, I'd be glad to hear it. ORDER BY only supports ASC/DSC.
This is a very crude example, but it demonstrates how such a feature might work:
Of course, here's some things you could do to improve it:
1) Make the field you use dynamic (requires a ton of extra work, though...)
2) Improve the algorithm used to select a value (I'd recommend a map...)
3) Improve the UI so that users can simply click-and-drag values, or use buttons or something else.
4) Store the sorted order in a field on the record, so you can use ORDER BY for default ordering when the page loads.
... Tons of ways this could be improved, but I wanted to show that custom sorting can be done. This works by virtue of using the account's name as the sort key; when you juggle around the values in the text boxes and hit "sort", it will cause the page block below to show the new ordering.