We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to create a simple pivot grid?

Hi,

I have gone through your Pivot grid sample and it looks good. But, how do I use this control? From what I understand, the user can drag and drop columns onto the pivoting areas to get the grid pivoted. What if I want the pivoting to be done programatically? Can this be achieved? Actually, I have a grid which is bound to an IList data source and I have no knowledge of the columns.

Moreover, if I use this pivot grid in an enterprise application, do you give full support for the component?

Thanks,
Nihar.


2 Replies

NR Nihar Ranjan Dalai June 7, 2011 10:53 AM UTC

Hi,

To be a bit elaborate, I wish to achieve the following things using your Pivot Grid Control. I am using the Pivot Grid Demo present in your sample browser as a reference implementation.

1) I need to have pivoting based on two columns. In the first snapshot attached, it is done on the columns - State and City. The remaining columns should be visible as data rows, only that their values should contain the sum of the individual cells (for all columns), as is shown in the snapshot.

2) I need to do all pivoting programmatically and not by using drag and drop.

3) I need to be able to select all the rows for the category by clicking on the pivoted cell(or on the row header if available).

4) Drop areas are required to be hidden.

5) On clicking a any data cell, whole row should be selected.

6) Single cell selection should be disabled.

Please find attached a snapshot of the expected pivot grid control.

Thanks,
Nihar.



pivoting_expected_b6d5dfa3.zip


JJ Jisha Joy Syncfusion Team June 14, 2011 05:28 AM UTC

Hi Nihar,

The pivot grid comprises of the following components.


Display Grid - Displays the data extracted from the underlying database.

Pivot Table Field List - Lists the available fields from the database. Provides a way to add/remove the fields to/from the grid.

Drag-Drop Areas - Serves as a view state of the pivot grid, where you can rearrange the fields by doing a drag-and-drop operation between the row and column label areas.

The following code allows us to display the values as desired to be populated in the main grid. Please refer to the following code in the PivotGridControl.cs file.

void gridFields_CheckBoxClick(object sender, GridCellClickEventArgs e)
{
int rowIndex = e.RowIndex < 2 ? 2 : e.RowIndex;
if (gridFields[rowIndex, 0].Text == "0")
{
//this.gridRows.RowCount++;
//this.gridRows[this.gridRows.RowCount, 0].Text = gridFields[e.RowIndex, 0].Description;
this.gridRows.Rows.InsertRange(this.gridRows.RowCount, 1);
this.gridRows[this.gridRows.RowCount - 1, 0].Text = gridFields[rowIndex, 0].Description;
this.gridRows.Refresh();
PerformLayout(gridRows, null);
}
else
{
int location;
for (int i = 0; i < 4; i++)
{
GridList grid = FindField(gridFields[rowIndex, 0].Description, out location) as GridList;
if (grid != null && location != -1)
{
grid.Rows.RemoveRange(location, location);
PerformLayout(grid, null);
}
}
}
}
You can prevent the cell selection and allow row selection when clicking on the cell by setting the following properties,

gridMainDisplay.ListBoxSelectionMode = SelectionMode.One;
gridMainDisplay.AllowSelection = GridSelectionFlags.None;

Regards,
Jisha



Loader.
Live Chat Icon For mobile
Up arrow icon