Replies
Wow your example is working perfectly. Thank you very much.
Mohandas PK
Hi,
Please check the sample code from this link
https://drive.google.com/open?id=0B6oOTBj9qI4cek5lVFJtazZuUTQ
This sample contains a Web Hierarchical Grid, it populated dynamically on demand.
The parent grid with state data working perfectly, it allows me to sort and filter.
But sorting and filtering is not working in the child grid.
Please check it .
Hi,
Here is my markup.
<div>
<ig:WebHierarchicalDataGrid ID="WHDG" runat="server" Height="800px" Width="100%" DataKeyFields="Year" ShowFooter="True"
oninitializerow="WHDG_InitializeRow"
onprerender="WHDG_PreRender"
onrowislandspopulating="WHDG_RowIslandsPopulating" OnDataBound="WHDG_DataBound" OnInitializeBand="WHDG_InitializeBand" OnRowIslandDataBinding="WHDG_RowIslandDataBinding" >
<Behaviors>
<ig:ColumnResizing EnableInheritance="True">
</ig:ColumnResizing>
<ig:Sorting EnableInheritance="True">
</ig:Sorting>
<ig:Activation>
</ig:Activation>
<ig:Filtering EnableInheritance="True" FilterType="ExcelStyleFilter">
</ig:Filtering>
</Behaviors>
</ig:WebHierarchicalDataGrid>
</div>
Here I enabled sorting with inheritance , but it works only in parent grid, All child grids are generated dynamically.
Every thing is working fine with out sorting and filtering.
Hi, I am unable to set the columns as sortable. Could you please provide a sample code for the same?
My Excel style filtering is also not working for child Grids (But sort and filtering is working perfectly for the first parent grid)
Please give me some suggestion or a sample code.
My code as follows
private void BindSecondLevel(Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e)
{
String key = e.Row.DataKey[0].ToString();
txtYear.Text = e.Row.Items[0].Text.ToString();
DataSet dsData = new DataSet();
CmsBusinessRepository bs = new CmsBusinessRepository();
dsData = bs.GetInvoiceDataByLevel(2, key, txtFrom.Text.ToString(), txtTo.Text.ToString(), "0", Datetype);
ContainerGrid childGrid = new ContainerGrid();
e.Row.RowIslands.Add(childGrid);
childGrid.DataKeyFields = "CustomerId";
childGrid.AutoGenerateColumns = false;
childGrid.Level = 1;
childGrid.DataSource = dsData;
childGrid.Key = "CustomerSummary";
childGrid.Behaviors.CreateBehavior<Sorting>();
childGrid.Behaviors.Sorting.Enabled = true;
SortingColumnSetting scs2 = new SortingColumnSetting();
scs2.ColumnKey = "Tax";
scs2.Sortable = false;
childGrid.Behaviors.Sorting.ColumnSettings.Add(scs2);
childGrid.Behaviors.CreateBehavior<Filtering>();
childGrid.Behaviors.Filtering.Enabled = true;
childGrid.Behaviors.Filtering.ApplyFilter();
BoundDataField CustomerId = new BoundDataField();
CustomerId.DataFieldName = "CustomerId";
CustomerId.Key = "CustomerId";
CustomerId.Header.Text = "ID";
CustomerId.Header.CssClass = "igg_HeaderNumericLevelTwo";
CustomerId.Width = Unit.Percentage(2.5);
CustomerId.CssClass = "igMainCellsAlignLeft";
childGrid.Columns.Add(CustomerId);
BoundDataField Customer = new BoundDataField();
Customer.DataFieldName = "Customer";
Customer.Key = "Customer";
Customer.Header.Text = "CUSTOMER";
Customer.Header.CssClass = "igg_HeaderNumericLevelTwo";
Customer.Width = Unit.Percentage(10);
Customer.CssClass = "igMainCellsAlignLeft";
childGrid.Columns.Add(Customer);
BoundDataField Subtotal = new BoundDataField();
Subtotal.DataFieldName = "Subtotal";
Subtotal.Key = "Subtotal";
Subtotal.Header.Text = "MERCH-PRICE";
Subtotal.Header.CssClass = "igg_HeaderNumericLevelTwo";
Subtotal.Width = Unit.Percentage(6);
Subtotal.DataFormatString = "{0:c2}";
Subtotal.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(Subtotal);
BoundDataField FreightCharge = new BoundDataField();
FreightCharge.DataFieldName = "FreightCharge";
FreightCharge.Key = "FreightCharge";
FreightCharge.Header.Text = "FREIGHT CHARGE";
FreightCharge.Header.CssClass = "igg_HeaderNumericLevelTwo";
FreightCharge.Width = Unit.Percentage(6);
FreightCharge.DataFormatString = "{0:c2}";
FreightCharge.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(FreightCharge);
BoundDataField Tax = new BoundDataField();
Tax.DataFieldName = "Tax";
Tax.Key = "Tax";
Tax.Header.Text = "TAX";
Tax.Header.CssClass = "igg_HeaderNumericLevelTwo";
Tax.Width = Unit.Percentage(5);
Tax.DataFormatString = "{0:c2}";
Tax.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(Tax);
BoundDataField MiscellaneousCharge = new BoundDataField();
MiscellaneousCharge.DataFieldName = "MiscellaneousCharge";
MiscellaneousCharge.Key = "MiscellaneousCharge";
MiscellaneousCharge.Header.Text = "MISC CHARGES";
MiscellaneousCharge.Header.CssClass = "igg_HeaderNumericLevelTwo";
MiscellaneousCharge.Width = Unit.Percentage(7);
MiscellaneousCharge.DataFormatString = "{0:c2}";
MiscellaneousCharge.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(MiscellaneousCharge);
BoundDataField Discount = new BoundDataField();
Discount.DataFieldName = "Discount";
Discount.Key = "Discount";
Discount.Header.Text = "DISCOUNT";
Discount.Header.CssClass = "igg_HeaderNumericLevelTwo";
Discount.Width = Unit.Percentage(6);
Discount.DataFormatString = "{0:c2}";
Discount.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(Discount);
BoundDataField Totalamount = new BoundDataField();
Totalamount.DataFieldName = "Totalamount";
Totalamount.Key = "Totalamount";
Totalamount.Header.Text = "TOTAL AMOUNT";
Totalamount.Header.CssClass = "igg_HeaderNumericLevelTwo";
Totalamount.Width = Unit.Percentage(7);
Totalamount.DataFormatString = "{0:c2}";
Totalamount.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(Totalamount);
BoundDataField CreditMemo = new BoundDataField();
CreditMemo.DataFieldName = "CreditMemo";
CreditMemo.Key = "CreditMemo";
CreditMemo.Header.Text = "CREDIT MEMO";
CreditMemo.Header.CssClass = "igg_HeaderNumericLevelTwo";
CreditMemo.Footer.CssClass = "igg_Footer";
CreditMemo.Width = Unit.Percentage(7);
CreditMemo.DataFormatString = "{0:c2}";
CreditMemo.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(CreditMemo);
BoundDataField DebitMemo = new BoundDataField();
DebitMemo.DataFieldName = "DebitMemo";
DebitMemo.Key = "DebitMemo";
DebitMemo.Header.Text = "DEBIT MEMO";
DebitMemo.Header.CssClass = "igg_HeaderNumericLevelTwo";
DebitMemo.Footer.CssClass = "igg_Footer";
DebitMemo.Width = Unit.Percentage(7);
DebitMemo.DataFormatString = "{0:c2}";
DebitMemo.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(DebitMemo);
BoundDataField SUBTOTALCOST = new BoundDataField();
SUBTOTALCOST.DataFieldName = "Subtotalcost";
SUBTOTALCOST.Key = "Subtotalcost";
SUBTOTALCOST.Header.Text = "SUBTOTAL COST";
SUBTOTALCOST.Header.CssClass = "igg_HeaderNumericLevelTwo";
SUBTOTALCOST.Footer.CssClass = "igg_Footer";
SUBTOTALCOST.Width = Unit.Percentage(7);
SUBTOTALCOST.DataFormatString = "{0:c2}";
SUBTOTALCOST.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(SUBTOTALCOST);
BoundDataField DUTY_COST = new BoundDataField();
DUTY_COST.DataFieldName = "DUTYCOST";
DUTY_COST.Key = "DUTYCOST";
DUTY_COST.Header.Text = "DUTY COST";
DUTY_COST.Header.CssClass = "igg_HeaderNumericLevelTwo";
DUTY_COST.Footer.CssClass = "igg_Footer";
DUTY_COST.Width = Unit.Percentage(6);
DUTY_COST.DataFormatString = "{0:c2}";
DUTY_COST.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(DUTY_COST);
BoundDataField TOTAL_FREIGHT_COST = new BoundDataField();
TOTAL_FREIGHT_COST.DataFieldName = "TOTALFREIGHTCOST";
TOTAL_FREIGHT_COST.Key = "TOTALFREIGHTCOST";
TOTAL_FREIGHT_COST.Header.Text = "TOTAL FREIGHT COST";
TOTAL_FREIGHT_COST.Header.CssClass = "igg_HeaderNumericLevelTwo";
TOTAL_FREIGHT_COST.Footer.CssClass = "igg_Footer";
TOTAL_FREIGHT_COST.Width = Unit.Percentage(7);
TOTAL_FREIGHT_COST.DataFormatString = "{0:c2}";
TOTAL_FREIGHT_COST.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(TOTAL_FREIGHT_COST);
BoundDataField PROFIT = new BoundDataField();
PROFIT.DataFieldName = "PROFIT";
PROFIT.Key = "PROFIT";
PROFIT.Header.Text = "PROFIT";
PROFIT.Header.CssClass = "igg_HeaderNumericLevelTwo";
PROFIT.Footer.CssClass = "igg_Footer";
PROFIT.Width = Unit.Percentage(5);
PROFIT.DataFormatString = "{0:c2}";
PROFIT.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(PROFIT);
BoundDataField PROFIT_PER = new BoundDataField();
PROFIT_PER.DataFieldName = "PROFITPER";
PROFIT_PER.Key = "PROFITPER";
PROFIT_PER.Header.Text = "PROFIT-%";
PROFIT_PER.Header.CssClass = "igg_HeaderNumericLevelTwo";
PROFIT_PER.Footer.CssClass = "igg_Footer";
PROFIT_PER.Width = Unit.Percentage(4);
PROFIT_PER.DataFormatString = "{0:N2}";
PROFIT_PER.CssClass = "igCellsAlignRight";
childGrid.Columns.Add(PROFIT_PER);
childGrid.DataBind();
}
Regards,
Mohandas Pk
Hi,
I created a similar example based on the on demand example shared in this thread up to 6 levels and it working perfectly. But I need to add calculated footer values to every level.
Trying to access the Footer object I got null exception. Please help me to resolve this.
Here is my code…..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using Infragistics.Web.UI.GridControls;
using dbTask;
public partial class InfraReports_BalanceSheetRep : System.Web.UI.Page
{
private string _connStr = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (txtFrom.Text.ToString() == "") { txtFrom.Text = "01/01/" + Convert.ToString(DateTime.Now.Year); }
if (txtTo.Text.ToString() == "") { txtTo.Text = "06/30/2017"; }
BindGrid();
}
protected void WHDG_InitializeRow(object sender, Infragistics.Web.UI.GridControls.RowEventArgs e)
{
// don't show the arrow for the last level
if (((ContainerGridRecord)e.Row).Level < 5)
((ContainerGridRecord)e.Row).IsEmptyParent = true;
}
protected void WHDG_RowIslandsPopulating(object sender, Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e)
{
//Cancel the default automatic load on demand operation
e.Cancel = true;
switch (e.Row.Level)
{
case 0:
BindSecondLevel(e);
break;
case 1:
BindThirdLevel(e);
break;
case 2:
case 3:
case 4:
BindFourthLevel(e.Row.Level, e);
break;
}
}
protected void WHDG_PreRender(object sender, EventArgs e)
{
if (!IsPostBack)
{
foreach (ContainerGridRecord row in WHDG.GridView.Rows)
{
row.IsEmptyParent = true;
}
}
}
private void BindGrid()
{
DataSet dsData = new DataSet();
BalanceSheetRepository bs = new BalanceSheetRepository();
dsData = bs.GetDataByLevel(1, "0", txtFrom.Text.ToString(), txtTo.Text.ToString());
WHDG.AutoGenerateColumns = true;
WHDG.ShowFooter = true;
WHDG.DataSource = dsData;
WHDG.DataBind();
// this.WHDG.GridView.Columns[0].Footer.Text = "Sample footer text";
}
private void BindSecondLevel(Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e)
{
// Get the data key
String key = e.Row.DataKey[0].ToString();
DataSet dsData = new DataSet();
BalanceSheetRepository bs = new BalanceSheetRepository();
dsData = bs.GetDataByLevel(2, key, txtFrom.Text.ToString(), txtTo.Text.ToString());
// Create Container Grid
ContainerGrid childGrid = new ContainerGrid();
e.Row.RowIslands.Add(childGrid);
// Bind Grid
childGrid.DataKeyFields = "AccountTypeId";
childGrid.ShowFooter = true;
childGrid.Level = 1;
childGrid.DataSource = dsData;
childGrid.DataBind();
}
private void BindThirdLevel(Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e)
{
// Get the data key
String key = e.Row.DataKey[0].ToString();
DataSet dsData = new DataSet();
BalanceSheetRepository bs = new BalanceSheetRepository();
dsData = bs.GetDataByLevel(3, key, txtFrom.Text.ToString(), txtTo.Text.ToString());
// Create Container Grid
ContainerGrid childGrid = new ContainerGrid();
e.Row.RowIslands.Add(childGrid);
// Bind Grid
childGrid.DataKeyFields = "ScheduleId";
childGrid.Level = 2;
childGrid.DataSource = dsData;
childGrid.DataBind();
}
private void BindFourthLevel(int level, Infragistics.Web.UI.GridControls.ContainerRowCancelEventArgs e)
{
// Get the data key
String key = e.Row.DataKey[0].ToString();
DataSet dsData = new DataSet();
BalanceSheetRepository bs = new BalanceSheetRepository();
dsData = bs.GetDataByLevel((level + 2), key, txtFrom.Text.ToString(), txtTo.Text.ToString());
// Create Container Grid
ContainerGrid childGrid = new ContainerGrid();
e.Row.RowIslands.Add(childGrid);
// Bind Grid
if (level == 2) {
childGrid.DataKeyFields = "AccountId";
childGrid.Level = 3;
}
else if (level == 3){
childGrid.DataKeyFields = "LedgerId";
childGrid.Level = 4;
}
else if (level == 4)
{
childGrid.DataKeyFields = "LedgerId";
childGrid.Level = 5;
}
childGrid.DataSource = dsData;
childGrid.DataBind();
}
protected void WHDG_DataBound(object sender, EventArgs e)
{
double total = 0;
foreach (ContainerGridRecord row in this.WHDG.GridView.Rows)
{
total += Convert.ToDouble(row.Items[2].Text.Trim());
}
// this.WHDG.GridView.Columns[0].Footer.Text = total.ToString();
// this.WHDG.GridView.Band.Bands[0].Bands[0].Columns["Balance"].Footer.Text = total.ToString();
}
protected void WHDG_RowIslandsPopulated(object sender, ContainerRowEventArgs e)
{
e.Row.RowIslands[0].Columns[0].Footer.Text = "Sample footer text";
e.Row.RowIslands[0].ShowFooter = true;
}
}