2012-04-11 4 views
0

Extjs 3.4를 사용합니다. 서버 측에서는 임의의 구조 (다른 열, 행)로 datatable을 반환하는 메서드가 있습니다.extjs 그리드에 C# 데이터 테이블 넣기

extjs 그리드로 하나의 자바 스크립트 파일을 준비하고 싶습니다.이 파일은 모든 데이터 테이블을 가져 와서이 그리드에 표시 할 수 있습니다.

(나는 데이터 테이블 구조를 알게되면, 나는 jsonReader는 데이터 그리드에 생성하고 난 데이터 테이블에서 날짜와 JSON을 보낼 수 있습니다. 그러나 여기, 나는 그것을 해결하는 방법을 아무 생각이 없다)

이 그것을 할 수 있는가를? 그렇다면 어떻게?

답변

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; 
} 

여기 데모 http://ext4all.com/post/extjs-3-how-to-put-c-datatable-to-extjs-grid

관련 문제