コード例 #1
0
    private void orderTableByColumValue(TableLayout table, int colNum)
    {
        TableLayout             tempTable       = table;
        Dictionary <int, float> rowsToColValues = new Dictionary <int, float>();

        for (int i = 0; i < table.Rows.Count; i++)
        {
            TableRow currentRow  = table.Rows[i];
            string   stringValue = currentRow.Cells[colNum].GetComponentInChildren <Text>().text;
            float    floatValue  = float.Parse(stringValue, CultureInfo.InvariantCulture.NumberFormat);
            //  int intValue = (int)Math.Floor(floatValue);
            rowsToColValues[i] = floatValue;
        }

        Dictionary <int, int> rowMapper = new Dictionary <int, int>();
        var ordered = rowsToColValues.OrderBy(x => x.Value);
        int index   = 0;

        foreach (var item in ordered)
        {
            rowMapper[index] = item.Key;
            index++;
        }
        table.ClearRows();
        for (int i = 0; i < tempTable.Rows.Count; i++)
        {
            table.Rows[i] = tempTable.Rows[rowMapper[i]];
        }
        // Destroy(tempTable);
        table.CalculateLayoutInputVertical();
        table.UpdateLayout();
    }