How to use json subitems in Material Table with sorting

Asked
Active3 hr before
Viewed126 times

4 Answers

materialsortingtable
90%

Unity does not support passing other types directly to the API, such as primitive types or arrays, If you need to convert those, wrap them in a class or struct of some sort

Example_snippet/controller/utility/_sorting.js/ [Serializable] public class My. . .
[Serializable]
public class MyClass {
   public int level;
   public float timeElapsed;
   public string playerName;
}
load more v
88%

Nested object data (arrays) , Javascript sourced data ,The example below shows DataTables reading information for the columns from nested objects and arrays, where the structure of the row's data source in this example is:,This table loads data by Ajax, The latest data that has been loaded is shown below

Example_snippet/controller/utility/_sorting.js/ { "name": "Tiger Nixon", "hr. . .
{
   "name": "Tiger Nixon",
   "hr": {
      "position": "System Architect",
      "salary": "$3,120",
      "start_date": "2011/04/25"
   },
   "contact": [
      "Edinburgh",
      "5421"
   ]
}
72%

Example_snippet/controller/utility/_sorting.js/ const initialSelection = []; c. . .
const initialSelection = [];
const allowMultiSelect = true;
this.selection = new SelectionModel<MyDataType>(allowMultiSelect, initialSelection);
65%

Sort does NOT work by itself, In typescript define,So you get a reference to MatSort and just sort the items yourself by subscribing to the changes + rendering rows of the table

Example_snippet/controller/utility/_sorting.js/ @ViewChild(MatSort) sort: MatS. . .
@ViewChild(MatSort) sort: MatSort;
@ViewChild(MatTable) table: MatTable<any>;
private unsubscribe: Subject<void> = new Subject();

ngAfterViewInit() {
 this.sort.sortChange.pipe(takeUntil(this.unsubscribe)).
      subscribe(() => this.sortTable());
}

private sortTable() {
// Use this.sort.active (column name, e.g. 'width', this.sort.direction (string 'asc' or 'desc') 
// to sort the array of your items and call
 this.table.renderRows();
}

ngOnDestroy() {
   this.unsubscribe.next();
   this.unsubscribe.complete();
}