public void deleteColumn(string columnName) { //删除表头 _titles.Remove(columnName); //删除索引 _table.Remove(columnName); //删除数据 foreach (var item in _columnData.typeEntryMap) { bool hasDeleted = false; for (int i = 0; i < item.Value.Count; i++) { IColumnData colomndata = item.Value[i] as IColumnData; if (colomndata != null) { if (colomndata.title == columnName) { hasDeleted = true; item.Value.RemoveAt(i); break; } } } if (hasDeleted) { break; } } }
public void modify(string title, int rowIndex, IGridData iData) { if (_table.ContainsKey(title)) { IColumnData columnData = _table[title]; columnData.modify(rowIndex, iData); } else { Debug.LogError("Modify SheetData error: no that title:" + title); } }
//将序列化的数据载入索引 public void loadData() { _table.Clear(); foreach (var item in _columnData.typeEntryMap) { for (int columnIndex = 0; columnIndex < item.Value.Count; columnIndex++) { IColumnData columnData = item.Value[columnIndex] as IColumnData; if (_table.ContainsKey(columnData.title)) { Debug.LogError("LoadData error: find duplicate title:" + columnData.title); } else { _table.Add(columnData.title, columnData); } } } }
/// <summary> /// add a new column /// </summary> public void insertColumn(string name, E_DATA_TYPE dataType, int index = -1) { if (String.IsNullOrEmpty(name)) { Debug.LogError("Invalid title name!"); return; } if (_table.ContainsKey(name)) { Debug.LogError("Add Column Error: title name exists"); return; } //反射创建一个IColumnData Type columnType = DataTypeManager.instance.getColumnType(dataType); if (columnType != null) { IColumnData newColumn = (IColumnData)Activator.CreateInstance(columnType, new object[] { rowCount }); newColumn.title = name; _table.Add(name, newColumn); _columnData.typeEntryMap[dataType].Add(newColumn); //插入title if (index >= 0 && index < _titles.Count) { _titles.Insert(index, name); } else { _titles.Add(name); } } }