0

I use Extjs 3.4. In server side I have method which returns datatable with random structure (different columns, rows).

I want to prepare one javascript file with extjs grid, which could take any datatable and show it in this grid.

(When I know datatable structure, I create jsonReader to datagrid and I send json with date from datatable. But here, I have no idea how resolve it)

Is it possible to do it? If yes, how?

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
nirmus
  • 4,913
  • 9
  • 31
  • 50

1 Answers1

0
public static List<Dictionary<string, object>> ToJsonStructure(this DataTable table)
{
    if (table == null) throw new ArgumentNullException("table");

    List<Dictionary<string, object>> data = new List<Dictionary<string, object>>();
    Dictionary<string, object> obj;

    foreach (DataRow r in table.Rows)
    {
        obj = new Dictionary<string, object>();

        foreach (DataColumn c in table.Columns)
        {
            obj[c.ColumnName] = r[c.ColumnName];
        }

        data.Add(obj);
    }

    return data;
}

Demo here http://ext4all.com/post/extjs-3-how-to-put-c-datatable-to-extjs-grid

khmurach
  • 484
  • 4
  • 10