i am trying to build out a datatable that will sort based upon fields.
my object is
data class Meal(
val calories: Int,
val salad: String,
val mainCourse: String,
val desert: String,
)
backing list for the table would be
val mealList = listOf<Meal>(
Meal(calories = 10, salad = "Caesar Salad", mainCourse = "Salmon", desert = "pudding"),
Meal(calories = 20, salad = "Garden Salad", mainCourse = "Eggs", desert = "ice cream"),
Meal(calories = 30, salad = "Tuna Salad", mainCourse = "Chicken", desert = "pie"),
Meal(calories = 40, salad = "Potato Salad", mainCourse = "Hot Dogs", desert = "cake"),
Meal(calories = 40, salad = "Cobb Salad", mainCourse = "Steak", desert = "jello"),
)
was going to use somthing like this to hold the sorted data for the table
data class DataTableData<T>(
var items:List<T>,
var fieldList:MutableList<KProperty1<T, *>> = mutableListOf(),
){
fun handleSortRequest( incoming : KProperty1<T, *>){
fieldList.add(incoming)
items = items.sortedWith(compareBy(fieldList))
}
}
i can’t figure out how to sort the items based upon fieldList