예제 #1
0
파일: Util.cs 프로젝트: mhasham/Jq.Grid
        internal static JsonResponse PrepareJsonResponse <TEntity>(JsonResponse response, JQGrid grid, IQueryable <TEntity> data) where TEntity : class
        {
            if (response.records == 0 && !grid.AppearanceSettings.ShowFooter)
            {
                return(response);
            }
            PropertyInfo[] properties = typeof(TEntity).GetProperties(BindingFlags.Instance | BindingFlags.Public);
            int            i          = 0;

            foreach (object c in data)
            {
                List <string> array = new List <string>();
                foreach (JQGridColumn t in grid.Columns)
                {
                    bool fieldFound = false;
                    if (!string.IsNullOrEmpty(t.DataField))
                    {
                        foreach (PropertyInfo prop in properties)
                        {
                            if (t.DataField.ToLower().Equals(prop.Name.ToLower()))
                            {
                                fieldFound = true;
                                if (prop.GetValue(c, null) != null)
                                {
                                    object val  = prop.GetValue(c, null);
                                    string text = (string.IsNullOrEmpty(t.DataFormatString) ? val.ToString() : t.FormatDataValue(val, t.HtmlEncode));
                                    array.Add(text);
                                }
                                else
                                {
                                    array.Add("");
                                }
                                break;
                            }
                        }
                        if (!fieldFound)
                        {
                            array.Add("");
                        }
                    }
                }
                string  id      = array[Util.GetPrimaryKeyIndex(grid)];
                JsonRow jsonRow = new JsonRow();
                jsonRow.id       = id;
                jsonRow.cell     = array.ToArray();
                response.rows[i] = jsonRow;
                i++;
            }
            return(response);
        }
예제 #2
0
파일: Util.cs 프로젝트: mhasham/Jq.Grid
        private static JsonRow[] FillColumn(IQueryable data, PropertyInfo[] properties, List <JQGridColumn> columns, int id)
        {
            List <JsonRow> result = new List <JsonRow>();

            foreach (object c in data)
            {
                List <string> array = new List <string>();
                foreach (JQGridColumn column in columns)
                {
                    array.Add(BindValue(column.DataField, c, properties, column));
                }
                string  RowId   = array[id];
                JsonRow jsonRow = new JsonRow();
                jsonRow.id   = RowId;
                jsonRow.cell = array.ToArray();
                result.Add(jsonRow);
            }
            return(result.ToArray());
        }
예제 #3
0
파일: Util.cs 프로젝트: mhasham/Jq.Grid
 internal static JsonResponse PrepareJsonResponse(JsonResponse response, JQGrid grid, DataTable dt)
 {
     for (int i = 0; i < dt.Rows.Count; i++)
     {
         string[] array = new string[grid.Columns.Count];
         for (int j = 0; j < grid.Columns.Count; j++)
         {
             JQGridColumn jQGridColumn = grid.Columns[j];
             string       text         = "";
             if (!string.IsNullOrEmpty(jQGridColumn.DataField))
             {
                 int ordinal = dt.Columns[jQGridColumn.DataField].Ordinal;
                 text = (string.IsNullOrEmpty(jQGridColumn.DataFormatString) ? dt.Rows[i].ItemArray[ordinal].ToString() : jQGridColumn.FormatDataValue(dt.Rows[i].ItemArray[ordinal], jQGridColumn.HtmlEncode));
             }
             array[j] = text;
         }
         string  id      = array[Util.GetPrimaryKeyIndex(grid)];
         JsonRow jsonRow = new JsonRow();
         jsonRow.id       = id;
         jsonRow.cell     = array;
         response.rows[i] = jsonRow;
     }
     return(response);
 }