Sorting rich:dataTable with second value in a column - sorting

I have a rich dataTable that has a column which contains the full name of a person (Last name, first Name). I currently have the table so that the columns can be sorted based on the last name of the person. However I want it so that if the last names are equal it will then sort by the first names next. Is this possible? How can I do it?
<rich:column sortBy="#{list.lastName}">
<h:outputLabel value="#{list.lastName} #{list.firstName}"/>
</rich:column>
Example:
If the names were (B Smith and A Smith)
Should be sorted:
Smith A
Smith B

That isn't possible with <rich:dataTable>.
You'd better add a (transient) getter which returns the "full name":
#Transient // Only if it's a JPA entity.
public String getFullName() {
return lastName + " " + firstName;
}
And then use it in sorting:
<rich:column sortBy="#{list.fullName}">

Related

Please can I have a Power Query formula to allow me to check if cells contain some text and then replace?

I have a list of residents who have different professions including being a student. However, some have written “Student” or “Overseas Student” or something else with the word student in it. I would like Power Query to search the column for any cell containing “Student” and replace it with “Student” so it removes any other references. Please can someone help?
I have tried to write the formula but no it have been successful.
You'll need to use the Text.Contains function, this will return a True/False, if the search text is in the column. You will need to then wrap it with a IF statement like:
if Text.Contains([Column1], "Student") then "Student" else [Column1]
Which will result in the following new column.
It's not clear from your question, if you want to replace items in a string with "I am a overseas student" to "I am a student", you'll have to use the replace & contains function, with a multiple if statement, to check what string you are searching for then replace that value.
You can Transform the column in Power Query: (You'll need to edit your M-Code in the Advanced Editor to add the #"Normalize Student" line)
Source
M Code
let
Source = Excel.CurrentWorkbook(){[Name="Table7"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Profession", type text}}),
//edit table and column name to reflect your actual variables
#"Normalize Student" = Table.TransformColumns(#"Changed Type", {
"Profession", each if Text.Contains(_, "student", Comparer.OrdinalIgnoreCase) then "Student" else _, type text
})
in
#"Normalize Student"
Result

Cast a column to a different type in PowerQuery

I have the following query to combined two fields of different types:
= Table.AddColumn(#"New Column", "Calculated Column", each [Age] + [#"New-Name"])
Age is a number, and New-Name is a text field. However, I would like to cast the Age to a text field to concatenate the two fields together. How would I do this?
Try this
= Table.AddColumn(#"New Column", "Calculated Column", each Text.From([Age]) & [#"New-Name"])
Text.From to cast as text
& to concatenate

Is there a function to search for partial text in cells

I have a function that searches a spreadsheet for a name I put in cell A1 and returns a column in that row
eg, if I enter Smith in A1 it will return all columns C´s where Column D contains Smith, I would also like it to return columns containing smith so if a cell as john smith it would also be returned,
this is what I have so far but it only returns Total match,
=FILTER(Results!C:C,Results!$D:$D=$A$1)
Hope someone can help,
Thanks in advance
I believe this is what you're trying to do:
=filter(Results!C:C,find(lower($A$1),lower(Results!D:D))>=0)
EDIT: adding the lower() function to make the comparison case insensitive.

MVC3 validation with data-annotation?

Is it possible to use a data-annotation attribute for dropdownlists to be valid, only if the user selects an option different from one with the value o (zero).
The option with value o (zero) is "Please Select an account", which is selected by default.
I used [Required] attribute to validate this dropdownlist, but it doesn't have any effect, because, how I said, by default the option with value o (zero)- "Please Select an account"- is selected.
Something like:
[Range(1, int.MaxValue, ErrorMessage = "Please enter a value bigger than {1}")]
public int Value { get; set; }
Making a drop-down list required does not make sense. What you want required is that the user pick a value other than zero from the drop-down list. So what should be required is the SelectedAccount property. You should use the MVC helper method to bind the drop-down selected value to the SelectedAccount property:
#Html.DropdownListFor(m => m.SelectedAccount, new SelectList(Model.Accounts))
I am probably off on the syntax but you can look that up.
Now with regards to your other issue of ensuring that the value is not zero. Is the account number represented as a number or can it contain non-numeric characters? If it is a number then you should represent it as such in your code. And if it is truly a string, then the first value of your drop-down list should be an empty string and not zero.
If you decide that it is a number, then use the Range annotation to ensure that the value is greater than zero:
[Required]
[Range(1, Int32.MaxValue)]
public string SelectedAccountNumber {get;set;}
Hope that helps!

Change the Sequence of JqGrid Columns

I wanted to change the grid column sequence dynamically. For e.g. By default the grid will be loaded in LoginId, FirstName and LastName sequence. Based on some condition, I need to change the FirstName and LastName sequence.
Is there any way I can do this?
I tried doing like:
{name:'UserName',index:'UserName',width:82,sortable:false},
if(true)
{
{name:'FirstName',index:'FirstName',width:65,sortable:false},
{name:'LastName',index:'LastName',width:65,sortable:false},
}
else
{
{name:'LastName',index:'LastName',width:65,sortable:false},
{name:'FirstName',index:'FirstName',width:65,sortable:false},
}
but I could not get this work.
You can use remapColumns function to do this. In the documentation of the function you will find the example which seems to be wrong, because indexes in the permutation array seem to be 1-based and not 0-based. Try to use:
$("#list").remapColumns([1,3,2],true,false);
or
$("#list").remapColumns([1,3,2,4,5,6,7,8,9],true,false);
if you want to change the order of the second and third from the total 9 columns.

Resources