コード例 #1
0
ファイル: Util.cs プロジェクト: thanyaammyy/thaitaesc
 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))
             {
                 Guard.IsNull(dt.Columns[jQGridColumn.DataField], "The column with DataField=" + jQGridColumn.DataField + " does not exist in the datasource.");
                 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 text2 = array[Util.GetPrimaryKeyIndex(grid)];
         for (int k = 0; k < grid.Columns.Count; k++)
         {
             JQGridCellBindEventArgs jQGridCellBindEventArgs = new JQGridCellBindEventArgs(array[k], k, i, text2, dt.Rows[i].ItemArray);
             grid.OnCellBinding(jQGridCellBindEventArgs);
             array[k] = jQGridCellBindEventArgs.CellHtml;
             grid.OnCellBound(jQGridCellBindEventArgs);
         }
         JsonRow jsonRow = new JsonRow();
         jsonRow.id       = text2;
         jsonRow.cell     = array;
         response.rows[i] = jsonRow;
     }
     return(response);
 }
コード例 #2
0
ファイル: JQGrid.cs プロジェクト: gorbach/jqgrid.net
        private void OnDataSourceViewSelectCallback(IEnumerable retrievedData)
        {
            // Call OnDataBinding only if it has not already been 
            // called in the PerformSelect method.
            //if (IsBoundUsingDataSourceID)
            //{
                //OnDataBinding(EventArgs.Empty);
            //}            
            // The PerformDataBinding method binds the data in the  
            // retrievedData collection to elements of the data-bound control.
            //PerformDataBinding(retrievedData);                                 

            int rows = Convert.ToInt32(HttpContext.Current.Request.QueryString["rows"]);
            int page = Convert.ToInt32(HttpContext.Current.Request.QueryString["page"]);
            string sortExpression = HttpContext.Current.Request.QueryString["sidx"];
            string sortDirection = HttpContext.Current.Request.QueryString["sord"];
            string search = HttpContext.Current.Request.QueryString["_search"];

            DataView view = GetDataTableFromIEnumerable(retrievedData).DefaultView;

            PerformSort(view, sortExpression, sortDirection);
            PerformSearch(view, search);
           
            DataTable dt = view.ToTable();
            int count = dt.Rows.Count;
            
            // NEED TO FIX THIS
            int total = (count > 0) ? Convert.ToInt32(Math.Ceiling((double)(count / rows))) : 0;
            if (total == 0) 
                total++;

            int startIndex = (page * rows) - rows;
            int endIndex = count > rows ? startIndex + rows : count;
            int rowCount = count > rows ? rows : count;

            JsonResponse response = new JsonResponse();
            response.page = page;
            response.total = total;
            response.records = count;
            response.rows = new JsonRow[rowCount];


            int index = 0;
            for (int i = startIndex; i < endIndex; i++)
            {
                object[] cells = new object[dt.Rows[i].ItemArray.Length];
                for (int j = 0; j < dt.Rows[i].ItemArray.Length; j++)
                {
                    cells[j] = dt.Rows[i].ItemArray[j];
                }

                JsonRow row = new JsonRow();
                row.id = cells[0].ToString();
                row.cell = cells;
                response.rows[index++] = row;
            }
            
            EmitResponse(_sr.Serialize(response));
        }
コード例 #3
0
ファイル: Util.cs プロジェクト: thanyaammyy/thaitaesc
 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))
             {
                 Guard.IsNull(dt.Columns[jQGridColumn.DataField], "The column with DataField=" + jQGridColumn.DataField + " does not exist in the datasource.");
                 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 text2 = array[Util.GetPrimaryKeyIndex(grid)];
         for (int k = 0; k < grid.Columns.Count; k++)
         {
             JQGridCellBindEventArgs jQGridCellBindEventArgs = new JQGridCellBindEventArgs(array[k], k, i, text2, dt.Rows[i].ItemArray);
             grid.OnCellBinding(jQGridCellBindEventArgs);
             array[k] = jQGridCellBindEventArgs.CellHtml;
             grid.OnCellBound(jQGridCellBindEventArgs);
         }
         JsonRow jsonRow = new JsonRow();
         jsonRow.id = text2;
         jsonRow.cell = array;
         response.rows[i] = jsonRow;
     }
     return response;
 }