This commit is contained in:
@@ -84,8 +84,11 @@ namespace AyaNova.DataList
|
||||
//WHERE CLAUSE - FILTER
|
||||
qWhere = DataListSqlFilterCriteriaBuilder.DataFilterToSQLCriteria(DataList.FieldDefinitions, TheFilter, DataList.FieldDefinitions, UserId);
|
||||
//ORDER BY CLAUSE - SORT
|
||||
//BUILD ORDER BY AND APPEND IT
|
||||
//BUILD ORDER BY
|
||||
qOrderBy = DataListSqlFilterOrderByBuilder.DataFilterToSQLOrderBy(DataList.FieldDefinitions, TheFilter);
|
||||
}else{
|
||||
//BUILD DEFAULT ORDER BY IF POSSIBLE
|
||||
qOrderBy = DataListSqlFilterOrderByBuilder.DataFilterToSQLOrderBy(DataList.FieldDefinitions, null);
|
||||
}
|
||||
|
||||
//LIMIT AND OFFSET CLAUSE - PAGING
|
||||
@@ -103,7 +106,7 @@ namespace AyaNova.DataList
|
||||
}
|
||||
else
|
||||
{
|
||||
qDataQuery = $"{qSelectColumns} {qFrom} {qLimitOffset}";
|
||||
qDataQuery = $"{qSelectColumns} {qFrom} {qOrderBy} {qLimitOffset}";
|
||||
qTotalRecordsQuery = $"SELECT COUNT(*) {qFrom}";
|
||||
}
|
||||
|
||||
|
||||
@@ -15,16 +15,19 @@ namespace AyaNova.DataList
|
||||
public static string DataFilterToSQLOrderBy(List<AyaDataListFieldDefinition> objectFieldsList, AyaNova.Models.DataListFilter dataFilter)
|
||||
{
|
||||
|
||||
if (string.IsNullOrWhiteSpace(dataFilter.Sort))
|
||||
if (dataFilter == null || string.IsNullOrWhiteSpace(dataFilter.Sort))
|
||||
{
|
||||
//sort by default field descending which should in theory always be the id column of the main object in the list
|
||||
//which should return the results to user with most recent records at the top if no sort order was specified
|
||||
if(objectFieldsList[0].FieldKey=="df"){
|
||||
if (objectFieldsList[0].FieldKey == "df")
|
||||
{
|
||||
return $"ORDER BY {objectFieldsList[0].SqlIdColumnName} DESC";
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
//no default column so no idea how to sort
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
Reference in New Issue
Block a user