Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How sort rows in a TableNode ? (Read 1107 times)
CanadaProgrammer
Full Member
***
Offline


I love YaBB 1G - SP1!

Posts: 113
Joined: Jun 30th, 2011
How sort rows in a TableNode ?
Jul 15th, 2011 at 4:16am
Print Post  
some of rows can expand and collapse. Is it possible only sort these rows can be expanded and collapsed or only sort these rows under a same head row (Header property is true) ?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How sort rows in a TableNode ?
Reply #1 - Jul 15th, 2011 at 6:06am
Print Post  
It doesn't seem possible to directly sort the rows at this time. You could copy the cells data, sort it, and assign it back to the rows instead. For example, this sorts the cells under a single header:

Code
Select All
private void diagram_CellClicked(object sender, CellEventArgs e)
{
	TableNode table = e.Table;
	TableNode.Row row = table.Rows[e.Row];
	if (row.Header && e.Column == 1)
	{
		List<string> sectionData = GetSectionData(table, e.Row);
		sectionData.Sort();
		SetSectionData(table, e.Row, sectionData);
	}
}

List<string> GetSectionData(TableNode table, int headerRow)
{
	List<string> data = new List<string>();
	for (int i = headerRow + 1; i < table.RowCount; ++i)
	{
		if (table.Rows[i].Header)
			break;
		data.Add(table[0, i].Text);
	}
	return data;
}

TableNode TestSortTable()
{
	TableNode table = diagram.Factory.CreateTableNode(
		0, 0, 40, 150,// bounds
		2, 8);// columns x rows
	table[0, 0].Text = "header 1";
	table[0, 1].Text = "z";
	table[0, 2].Text = "y";
	table[0, 3].Text = "x";
	table[0, 4].Text = "header 2";
	table[0, 5].Text = "b";
	table[0, 6].Text = "c";
	table[0, 7].Text = "a";

	table.Rows[0].Header = true;
	table[1, 0].Image = sortIcon;
	table.Rows[4].Header = true;
	table[1, 4].Image = sortIcon;
	table.OffsetHeaderRows = true;
	return table;
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint