示例#1
0
 internal static string ConvertToJson(JsonResponse response, JQGrid grid, DataTable dt)
 {
     object obj;
     if (response.records == 0)
     {
         obj = new object[0];
     }
     else
     {
         obj = Util.PrepareJsonResponse(response, grid, dt);
     }
     return new JavaScriptSerializer().Serialize(obj);
 }
示例#2
0
        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
 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;
 }
示例#4
0
 private void PerformRequestData(IEnumerable retrievedData)
 {
     DataView defaultView = this.GetDataTableFromIEnumerable(retrievedData).DefaultView;
     int num = Convert.ToInt32(this.QueryString["page"]);
     int num2 = Convert.ToInt32(this.QueryString["rows"]);
     string sortExpression = this.QueryString["sidx"];
     string sortDirection = this.QueryString["sord"];
     string search = this.QueryString["_search"];
     if (this._totalRows > 0)
     {
         this._selectArguments.TotalRowCount = this._totalRows;
     }
     if (this._filteredGridState != null && this.ExportSettings.ExportDataRange != ExportDataRange.FilteredAndPaged)
     {
         num = 1;
     }
     this.PerformSearch(defaultView, search);
     int num3 = (this._selectArguments.TotalRowCount > -1) ? this._selectArguments.TotalRowCount : defaultView.Count;
     int totalPagesCount = (int)Math.Ceiling((double)((float)num3 / (float)num2));
     if (!this._dataSourceSorted)
     {
         this.PerformSort(defaultView, sortExpression, sortDirection);
     }
     else
     {
         new JQGridSortEventArgs(sortExpression, sortDirection);
         this.OnSorted(new EventArgs());
     }
     DataTable dataTable = defaultView.ToTable();
     DataTable dataTable2 = dataTable;
     if ((num - 1) * num2 >= num3 && num > 1)
     {
         num--;
     }
     int startIndex = (num - 1) * num2;
     int num4 = (num - 1) * num2 + num2;
     if (num4 > num3)
     {
         num4 = num3;
     }
     if (num4 <= dataTable.Rows.Count)
     {
         dataTable2 = this.GetPagedDataTable(startIndex, num4, dataTable);
     }
     JQGrid.JQGridDataRequestedEventHandler jQGridDataRequestedEventHandler = (JQGrid.JQGridDataRequestedEventHandler)base.Events[JQGrid.EventDataRequested];
     if (jQGridDataRequestedEventHandler != null)
     {
         this.OnDataRequested(new JQGridDataRequestedEventArgs(dataTable2));
     }
     if (this.IsGridExportActive())
     {
         DataTable dataSource = dataTable;
         if (this.ExportSettings.ExportDataRange == ExportDataRange.FilteredAndPaged)
         {
             dataSource = dataTable2;
         }
         if (this._filteredExcelExportActive)
         {
             this.DoExportToExcel(this._filteredExportFileName, this._filteredGridState, dataSource);
         }
         if (this._filteredCSVExportActive)
         {
             this.DoExportToCSV(this._filteredExportFileName, this._filteredGridState, dataSource);
         }
         if (this._filteredExportActive)
         {
             this.DoExportGridData(this._filteredGridState, dataSource);
         }
         return;
     }
     if (this.TreeGridSettings.Enabled)
     {
         JsonTreeResponse response = new JsonTreeResponse(num, totalPagesCount, num3, num2, dataTable2.Rows.Count, Util.GetFooterInfo(this));
         HttpContext.Current.Response.SendResponse(Util.ConvertToTreeJson(response, this, dataTable));
         return;
     }
     JsonResponse response2 = new JsonResponse(num, totalPagesCount, num3, num2, dataTable2.Rows.Count, Util.GetFooterInfo(this));
     HttpContext.Current.Response.SendResponse(Util.ConvertToJson(response2, this, dataTable2));
 }