Share: Hierarchy DataGrid Solutions (Transfer)

xiaoxiao2021-03-06  19

DataGrid is very easy to use .NET web control, TreeView is also, but there is no mature control can integrate the advantages of both to express structure more complex data.

Denis Bauer offers a solution he called "hierarchy data" (http://www.denisbauer.com/aspnetcontrols/hierargrid.aspx), this program is very good, but you need to explain

1. The "Hierarchy DataGrid" implemented here is not the same as the structure of the MSHFlexGrid (ie, Microsoft Hierarchy FlexGrid) commonly used in VB 6. In the MSHFLEXGRID, the items of the parent layer are in parallel, while the sub-layer follows the right side of the parent layer (the columns of each layer are called one BAND). This implementation, the sublayer is to start like TreeView, and I think it is more appropriate to "treec".

2, "Hierarchy DataGrid" implemented here is that each layer makes a USER Control, while the class of Denis Bauer provides a universal call method from Page to User Control.

3, this implementation is a bad place is that it is difficult to implement the EDIT function. Because the parent layer only passes DataSource to the sublayer, the status in the sub-layer is not recorded, or the EditIndEx of the sub-DataGrid.

Svg brother implemented a TreeView, which is basically like a DataGrid, but the most left column like TreeView, can be dynamically expanded. His idea is to read data with JavaScript XMLHTTP, and then write the left column with JavaScript. The process of writing the left left, similar to the HTC file of the TreeView generated a method. The disadvantage of this method is that the code that is written is more, and when modifies the sub-data, the DataGrid has been implemented.

Recently, one project also made a similar requirement. At first I used Nested DataGrid, but the DataGrid of the nesting sub-layers did not belong to the same DataGrid, and they could not align between them. Later, I thought it was a method, successful.

In fact, it is not complicated to wear it. In MSDN's article "Http://msdn.microsoft.com/Workshop/Author/tables/buildtables.asp), relative to DOM (Document Object Model), with

, ,
These control table, you can also use Table Object Model to find Row, Cell, etc., to increase modification.

So, if I bind to generate such a form: Li Qiang Tianjin Tianjin Mathematics 80 Li Qiang Tianjin Tianjin Language 90 Li Qiang Tianjin Tianjin Music 70 Li Qiang Tianjin Tianjin Sport 60 Wang Daming Hebei Baoding Mathematics 90 Wang Daming Hebei Baoding Language 80 Chen Xiaogang Hunan Changsha Mathematics 90

Use the Table Object Model to delete the repetition and appropriately set the ROWSPAN value of the item that is reserved in the repeating item, the same Cell in Table is Merge. My solution is as follows:

1. Reference fcnathoscolumnmerge function in .aspx

2, declare οnlοad = "fcnathostablemerge ('strmyTableName') in .spx tag;"

3, then declare the JavaScript function FcnathostableMerge (StrtableName), where the FcNathoscolumnMerge is used to merge the form by column.

For example, the table above, you can write:

Function FcnathostableMemerge (Strtables)

{

Fcnathoshtvgcolumnmerge (Strtables, [0], [0, 1, 2], True, True, False;

}

Where [0] is merged in accordance with the value of the 0 column (starting from 0), [0, 1, 2] indicates that if the value of a few rows 0 column is the same, it combines its 0th, 1, And 2 columns.

The three TRUE / FALSE parameters in the parameter are to indicate whether there is header, footer, and paging lines.

This is merged above, it is ----------------------- | | Mathematics | 80 | | Li Qiang Tianjin Tianjin | Language | 90 | | Music | 70 | | | Sports | 60 | ----------------------- | Wang Daming Hebei Baoding | Mathematics | 90 | | 语文 | 80 | ----------------- | Chen Xiaogang Hunan Changsha | Mathematics | 90 | -----------------------

The benefits of doing this are, other parts, you can use the DataGrid control. DataGrid generated table, after the browser is used by Merge, it is very convenient to use DataGrid to Edit, Update, and INSERT data.

Also, the FcnathostableMerge function can call FcnathoscolumnMerge multiple times, but when Merge is from right left.

Attach the FcnathoscolumnMerge code as follows:

Function FcnathoscolumnMerge (StrgridId, Arrindexcol, Arrmergecol, Blhasheader, Blhasfooter, BlhaSpageLine)

{

VAR TBL = Document.all [strgridid];

VAR IH = 0;

VAR IF = 0;

IF (Blhasheader == True) IH ; if (Blhasfooter == True) IF ;

IF (blhaspagelineline == true) IF ;

TROWS = TBL.Children [0] .children

I0 = IH;

Strkey = new array (arrindexcol.length);

StrPRevkey = New Array (arRindexcol.length);

For (ii = 0; II

{

Strkey [II] = trows [IH] .children [ArrIndexcol [II]]. innerText;

StrPRevkey [II] = strkey [ii];

}

For (i = IH 1; i

{

Blequal = true;

For (ii = 0; II

{

Strkey [II] = trows [i] .children [arrIndexcol [ii]]. innerText;

IF (strkey [ii]! = StrPrevkey [II])

BLEQUAL = false;

}

IF (blequal == false)

{

For (ii = 0; II

TROWS [I0] .children [Arrmergecol [II]]. ROWSPAN = I-I0;

For (j = i0 1; j

For (II = arrmergecol.length-1; ii> = 0; ii -)

TROWS [J] .children [Arrmergecol [II]]. RemoveNode (TRUE);

I0 = i;

For (ii = 0; II

StrPRevkey [II] = strkey [ii];

}

}

For (ii = 0; II

TROWS [I0] .children [Arrmergecol [II]]. ROWSPAN = I-I0;

For (j = i0 1; j

For (II = arrmergecol.length-1; ii> = 0; ii -)

TROWS [J] .children [Arrmergecol [II]]. RemoveNode (TRUE);

Return;

}

转载请注明原文地址:https://www.9cbs.com/read-56662.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.037, SQL: 9