groupData method

List<List<DataItem>> groupData(
  1. List parameters
)

Part Extension of List<DataItem> to sort data

Implementation

List<List<DataItem>> groupData(List<dynamic> parameters) {
  if (parameters.isNotEmpty) {
    List<List<DataItem>> temp = [this];
    for (int i = 0; i < parameters.length; i++) {
      List separates = List.generate(length, (index) {
        return this[index].get(parameters[i]);
      }).toSet().toList();
      separates.sort((a, b) {
        if (a == null || b == null) {
          if (a == null) {
            a = 1;
            b = 1;
            return a.compareTo(0);
          } else {
            a = 0;
            b = 0;
            return a.compareTo(1);
          }
        } else if (a is DateTime || b is DateTime) {
          a = DateTimeUtils.toDateTime(a);
          b = DateTimeUtils.toDateTime(b);
          if (a == null) {
            a = 1;
            b = 1;
            return a.compareTo(0);
          }
          if (b == null) {
            a = 0;
            b = 0;
            return a.compareTo(1);
          }
          return a.compareTo(b);
        } else {
          return a.compareTo(b);
        }
      });
      List<List<DataItem>> store = [];
      for (List<DataItem> dTemp in temp) {
        for (dynamic separate in separates) {
          store.add(dTemp.where((element) {
            return element.get(parameters[i]) == separate;
          }).toList());
        }
      }
      temp = store;
    }
    return temp;
  }
  // Set<String> ids = map((e) => e.id).toSet();
  // retainWhere((x) => ids.remove(x.id));

  return [this];
}