I think you should be a bit more specific ^_^
C# linq
private int TypeValue(string type){
switch(type.ToLower()){
case "bird":
return 0;
case "flower":
return 1;
case "animal":
return 2;
case "vegitable":
return 3;
default:
return 100;
}
}
....
list = list.OrderBy(i=>TypeValue(i.type)).ThenBy(i=>i.newId);
list = list.skip(pageIndex * pageSize).take(pageSize);
c# DataTable
DataTable dt= new DataTable();
foreach (DataRow row in DT.Rows){
row("CalculatedColumnName") = TypeValue(row.type);
}
DataView dv = new DataView(dt);
dv.Sort = "CalculatedColumnName, newIdASC";
var paging = dv.AsEnumerable().skip(pageIndex * pageSize).take(pageSize)
Sql
Select *,
case type
when 'bird' then 0
when 'flower' then 1
when 'animal' then 2
when 'vegitable' then 3
end as TypeSort
from list
order by
case type
when 'bird' then 0
when 'flower' then 1
when 'animal' then 2
when 'vegitable' then 3
end
, newId
SQL with CTE
You will need to create this as a stored procedure
Sql
<pre lang="SQL">
with firstCTE as (
Select *,
case type
when 'bird' then 0
when 'flower' then 1
when 'animal' then 2
when 'vegitable' then 3
end as TypeSort
from list
),
secondCTE as (
select * ,
ROW_NUMBER() OVER (ORDER BY TypeSort, newId) AS RowNumber
from firstCTE
)
select * from secondCTE
where RowNumber >= (@PageStart * @PageSize) AND RowNumber < ((@PageStart+1) * @PageSize)
order by RowNumber
javascript
var sortbyVat= function(a, b){
a= a.VatRate;
b= b.VatRate;
if(a== b) return 0;
return a> b? 1:-1;
}
var sortbyPriceAndVat= function(a, b){
a= a.Price;
b= b.Price;
if(a== b) return sortbyVat(a,b);
return a> b? 1:-1;
}
...
array.sort(sortbyPriceAndVat);
Edit: updated c# for specific use