setTableDataSearch method

dynamic setTableDataSearch(
  1. dynamic tableName,
  2. dynamic context,
  3. dynamic paramother
)

Implementation

setTableDataSearch(tableName, context, paramother) {
  myLogAll('setTableDataSearch');
  dynamic tableInfo = _tableList[tableName];
  List tableData = tableInfo[gData];
  List columns = tableInfo[gColumns];
  dynamic searchValue = tableInfo[gSearch] ?? '';
  Set setData = {};

//get where
  var aWhere = '';
  //dynamic value0 = '';
  //dynamic value1 = '';
  //List param = [];
  dynamic other = paramother;

  if (other != null) {
    other = getMap(other);
    dynamic aTitle = other[gOther];
    if (aTitle != null) {
      dynamic data0 = whereList[aTitle];
      if (data0 != null) {
        aWhere = data0[gWhere] ?? '';
        /*if (aWhere.indexOf("=") > 0) {
          param = aWhere.split('=');
          value0 = param[1];
          value1 = value0;
          if (value0[0] == "'") {
            value1 = value1.substring(1, value1.length - 1);
          }
          param[1] = value1;

        }*/
      }
    }
  }
  List newData = getDataWhere(tableData, aWhere);

  //print('---------- setTableDataSearch 3');
  bool searchValueIsNull = isNull(searchValue);

  Map dataModified = tableInfo![gDataModified] ?? {};
  bool modified = !isNull(dataModified);

  Map dataModifiedInvalid = tableInfo![gDataModifiedInvalid] ?? {};
  bool modifiedinvalid = !isNull(dataModifiedInvalid);
  bool notModified = (!modified) && (!modifiedinvalid);
  Set keySet = {};
  for (int i = 0; i < columns.length; i++) {
    Map acol = columns.elementAt(i);
    if (acol[gInputType] == gHidden) {
      continue;
    }
    if (!isNull(acol[gShowrange]) && acol[gShowrange] != gTable) {
      continue;
    }
    keySet.add(acol[gId]);
  }
  var filterValueLower = searchValue.toString().toLowerCase();
  for (int j = 0; j < newData.length; j++) {
    Map dataRow = newData[j];
    if (searchValueIsNull) {
      setData.add(dataRow[gId]);
      continue;
    }

    bool filterExists = false;
    for (int i = 0; i < dataRow.entries.length; i++) {
      var key = dataRow.entries.elementAt(i).key;
      if (!keySet.contains(key)) {
        continue;
      }
      var aitem = dataRow[key];
      Map acol = getTableCol(tableName, key);
      var showTxt = getValueGUI(aitem, acol);
      if (showTxt.toString().toLowerCase().contains(filterValueLower)) {
        filterExists = true;
        break;
      }
    }
    if (filterExists) {
      setData.add(dataRow[gId]);
      continue;
    }
    if (notModified) {
      continue;
    }

    if (modified && !dataModified.containsKey(dataRow[gId])) {
      continue;
    }
    if (modifiedinvalid && !dataModifiedInvalid.containsKey(dataRow[gId])) {
      continue;
    }

    /*dynamic ti = getTableRowShowValueFilter(
        tableName, dataRow, columns, context, searchValue);
    if (ti != null) {
      if (param.length > 1) {
        if (ti[param[0]] == value1 || ti[param[0]] == value0) {
          setData.add(ti[gId]);
        }
      } else {
        setData.add(ti[gId]);
      }
    }*/
  }
  //print('---------- setTableDataSearch 4');
  if (isNull(setData) && !isNull(filterValueLower)) {
    setData.add('$gNull$gId');
  }
  tableInfo[gDataSearch] = setData;
  tableInfo[gRowCurrent] = 0;
  //print('setTableDataSearch tableInfo[gRowCurrent]  set to 0');
}