Aug 20, 2013, 7:38 PM
The code that takes 82 seconds is similar to the code i posted at 10:30 AM. The one where you can see //ALREADY CACHED. I intentionally created a repetition of that phrase in hopes that someone will make an impression that it's already cached. I guessed I was wrong.
<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>TreeGrid - Ext.NET Examples</title>
<script runat="server">
public class Entity
{
public string DataType
{
get;
set;
}
public string Label
{
get;
set;
}
public string Format
{
get;
set;
}
public string Title
{
get;
set;
}
public int Width
{
get;
set;
}
public string DataColumn
{
get;
set;
}
public bool Editable
{
get;
set;
}
}
protected void Page_Load(object sender, EventArgs e)
{
List<Entity> columns = new List<Entity>();
for (int i = 0; i < 40; i++)
{
Entity entity = new Entity
{
DataType = "text",
Title = "Column" + i,
Width = 100,
DataColumn = "Column" + i,
Editable = true
};
columns.Add(entity);
}
Application["TESTCOLUMNS"] = columns;
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Start();
for (int i = 0; i < 6; i++)
{
this.RenderGridMe();
}
watch.Stop();
X.Js.Alert(watch.ElapsedMilliseconds.ToString());
}
private void RenderGridMe()
{
//THIS IS CACHED ALREADY. THIS IS CACHED ALREADY. THIS IS CACHED ALREADY. THIS IS CACHED ALREADY
List<Entity> columns = Application["TESTCOLUMNS"] as List<Entity>;
GridPanel gridPanel = new GridPanel();
Store store = new Store();
//I WANT TO SKIP THIS PROCESS BECAUSE THIS IS THE ONE TAKING SO LONG..
// IS THERE A WAY TO REMEMBER THIS AFTER GOING THOUGH IT THE FIRST TIME?
//I BELIEVE ALL THESE INFO ARE ALREADY ON THE GridPanel.Config
foreach (Entity column in columns) // COLUMNS IS ON AVERAGE 40 items.
{
store.Fields.Add(column.DataColumn);
switch (column.DataType)
{
case "date":
case "datetime":
gridPanel.ColumnModel.Columns.Add(CreateDateColumn(column));
break;
case "text":
case "string":
gridPanel.ColumnModel.Columns.Add(CreateTextColumn(column));
break;
case "int":
case "bigint":
case "integer":
gridPanel.ColumnModel.Columns.Add(CreateNumberColumn(column));
break;
default:
gridPanel.ColumnModel.Columns.Add(CreateTextColumn(column));
break;
}
}
//END OF I WANT TO SKIP
gridPanel.Store.Add(store);
Viewport1.Items.Add(gridPanel);
}
private Column CreateNumberColumn(Entity entity)
{
Column column = new Column();
string label = entity.Label;
string format = entity.Format;
column.Text = entity.Title;
column.Sortable = true;
if (entity.Width == 0)
column.Flex = 1;
else
column.Width = Unit.Pixel(entity.Width);
column.DataIndex = entity.DataColumn;
column.Groupable = false;
if (entity.Editable)
{
Ext.Net.TextField textField = new Ext.Net.TextField();
column.Editor.Add(textField);
}
return column;
}
private Column CreateTextColumn(Entity entity)
{
Column column = new Column();
string label = entity.Label;
string format = entity.Format;
column.Text = entity.Title;
column.Sortable = true;
if (entity.Width == 0)
column.Flex = 1;
else
column.Width = Unit.Pixel(entity.Width);
column.DataIndex = entity.DataColumn;
column.Groupable = false;
if (entity.Editable)
{
Ext.Net.TextField textField = new Ext.Net.TextField();
column.Editor.Add(textField);
}
return column;
}
private DateColumn CreateDateColumn(Entity entity)
{
DateColumn column = new DateColumn();
string label = entity.Label;
string format = entity.Format;
column.Text = entity.Label;
column.Sortable = false;
column.Width = Unit.Pixel(100);
column.MaintainFlex = true;
column.DataIndex = entity.DataColumn;
column.Groupable = false;
if (entity.Editable)
{
Ext.Net.DateField dateField = new Ext.Net.DateField();
dateField.Format = format;
column.Editor.Add(dateField);
}
if (!string.IsNullOrWhiteSpace(format))
column.Renderer.Fn = ("Ext.util.Format.dateRenderer('" + format + "')");
return column;
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager runat="server" />
<ext:Viewport ID="Viewport1" runat="server">
</ext:Viewport>
</form>
</body>
</html>
Grids creating takes apprx. 4-6 ms on my computer. So, 82 sec is just unreal number for me.You are wrong in saying that it will not work as it actually worked.
Do you mean controls caching is working for you? Can you demonstrate it?
These lines of codes doesn't work and I am not sure what your response about it, as I have tried to bring this to your attention for a couple of times now but you kept ignoring it and instead you kept pointing out that i need to cache the database objects when i have already put //ALREADY CACHED so many times.