PDA

View Full Version : [CLOSED] Store Error



threewonders
Dec 30, 2014, 12:00 PM
Good.

In the example SimpleTask I added a command that displays a window. This window has within a grid, but no data is refreshed. I show the code.

The window opens correctly when clicking the command, the grid is created, but does not call LogGrid_RefreshData. Produce an error status code 200 OK status text {}




/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Command_Event(object sender, DirectEventArgs e)
{
string command = e.ExtraParams["command"];
int taskId;
int categoryID;

switch (command)
{
case "seguimiento":
new TaskWindowLog(int.Parse(e.ExtraParams["taskId"])).Render(this.Page.Form.ClientID, RenderMode.RenderTo);
break;
}
}



UI



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ext.Net;
using Task.Tasks.Classes.Model;

namespace Task.Tasks.Classes
{
public partial class TaskWindowLog : Window
{
/// <summary>
///
/// </summary>
private GridPanel gridPanel;

/// <summary>
///
/// </summary>
private Store store;

/// <summary>
///
/// </summary>
public TaskWindowLog()
{
this.Width = 800;
this.Height = 450;
this.Resizable = false;
this.Layout = "Border";
this.CloseAction = CloseAction.Destroy;

this.Buttons.Add(new Button("Cerrar"));

this.BuildGrid();
this.BuildStore();
this.BuildColumnModel();
}

/// <summary>
///
/// </summary>
private void BuildGrid()
{

this.gridPanel = new GridPanel
{
Region = Ext.Net.Region.Center
};

this.gridPanel.SelectionModel.Add(new RowSelectionModel
{
});


this.gridPanel.BottomBar.Add(new PagingToolbar
{

});

this.Items.Add(this.gridPanel);
}

/// <summary>
///
/// </summary>
private void BuildColumnModel()
{
GridHeaderContainer cm = this.gridPanel.ColumnModel;

cm.Columns.Add(new Column
{
Text = "Operaci?n",
Flex = 1,
Sortable = true,
DataIndex = "Title"
});

cm.Columns.Add(new Column
{
Text = "Creador",
Width = 120,
Sortable = true,
DataIndex = "IDUSRCreate",
Renderer = new Renderer(TaskWindowLog.SCOPE + ".renderCreate")
});

cm.Columns.Add(new DateColumn
{
Text = "Fecha",
Format = "dd/MM/yyyy HH:mm",
Width = 100,
Sortable = true,
DataIndex = "DateAdded"
});
}

/// <summary>
///
/// </summary>
private void BuildStore()
{
this.store = new Store
{
AutoLoad = true,
PageSize = 10,
Model =
{
new Ext.Net.Model
{
IDProperty = "AlertID",
Fields =
{
new ModelField("AlertID", ModelFieldType.Int),
new ModelField("TaskID", ModelFieldType.Int),
new ModelField
{
Name = "Tarea",
ServerMapping = "ag_Task.Title"
},
new ModelField("IDUSR", ModelFieldType.Int),
new ModelField("IDUSRCreate", ModelFieldType.Int),
new ModelField
{
Name = "UserName",
ServerMapping = "USRUSER.TxNombre"
},
new ModelField
{
Name = "UserApelli1",
ServerMapping = "USRUSER.TxApelli1"
},
new ModelField
{
Name = "UserNameC",
ServerMapping = "USRUSER1.TxNombre"
},
new ModelField
{
Name = "UserApelli1C",
ServerMapping = "USRUSER1.TxApelli1"
},
new ModelField("Title"),
new ModelField("Description"),
new ModelField("DateAdded", ModelFieldType.Date)
}
}
},
Sorters =
{
new DataSorter()
{
Property = "DateAdded",
Direction = SortDirection.DESC
}
},
GroupField = "DateAdded",
Proxy =
{
new PageProxy()
}
};

this.gridPanel.Store.Add(this.store);
}

}
}


Logic




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Task.Tasks.Classes.Model;

using Ext.Net.Utilities;
using Ext.Net;
using Task.Class;

namespace Task.Tasks.Classes
{
public partial class TaskWindowLog
{
/// <summary>
///
/// </summary>
private SimpleTasksDataContext DBContext
{
get
{
SimpleTasksDataContext ctx = new SimpleTasksDataContext();
ctx.DeferredLoadingEnabled = true;

return ctx;
}
}

/// <summary>
///
/// </summary>
public const string SCOPE = "SimpleTasks.TaskWindow";

/// <summary>
///
/// </summary>
private int taskId;

/// <summary>
///
/// </summary>
/// <param name="taskId"></param>
public TaskWindowLog(int taskId): this()
{
this.ID = "TaskWindowLog_" + taskId;
this.taskId = taskId;

SimpleTasksDataContext ctx = this.DBContext;

ag_Task task = (from t in ctx.ag_Task where t.TaskID == taskId select t).FirstOrDefault();

if (task != null)
{
this.Title = "Tarea - " + task.Title.Ellipsis(40);

this.CustomConfig.Add(new ConfigItem("taskId", taskId.ToString(), ParameterMode.Raw));

this.InitLogic();
}
else
{
this.Title = "Nueva Tarea";

this.CustomConfig.Add(new ConfigItem("taskId", taskId.ToString(), ParameterMode.Raw));

this.InitLogic();
}
}

/// <summary>
///
/// </summary>
private void InitLogic()
{
this.Buttons[0].Handler = new JFunction(this.ID + ".close();").ToScript();

this.store.ReadData += LogGrid_RefreshData;

Store store = this.store;
store.Parameters.Add(new StoreParameter("taskID", taskId.ToString(), ParameterMode.Value));
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void LogGrid_RefreshData(object sender, StoreReadDataEventArgs e)
{
int taskID = 0;

if (!int.TryParse(e.Parameters["taskID"], out taskID))
{
Ext.Net.X.Msg.Show(new MessageBoxConfig
{
Title = "Error",
Message = "Tarea sin informaci?n",
Icon = MessageBox.Icon.ERROR,
Buttons = MessageBox.Button.OK
});

return;
}

}
}
}



Any ideas ?? I am blocked.

A greeting !!

Daniil
Dec 31, 2014, 1:36 PM
Hi @threewonders,

This is a regular DirectEvent.

this.store.ReadData += LogGrid_RefreshData;

I mean a Store's ReadData event.

Any Ext.NET DirectEvent requires a control instance on server side. Otherwise, a DirectEvent cannot be executed and it throws an Exception like you see. You create the Store in one request, but the ReadData DirectEvent is another request. The Store is not recreated automatically.

There is no any simple way to overcome, but there is a few alternative ways to go.

1. Recreate the Store (actually, you might need to recreate the entire TaskWindowLog control). Here is some example with recreating controls.
http://forums.ext.net/showthread.php?24927&p=109918&viewfull=1#post109918

or

2. Use a PageProxy with a DirectFn.
http://examples2.ext.net/#/GridPanel/ArrayGrid/PageProxy_with_DirectMethod/

or

3. Use an AjaxProxy and refer to an HttpHandler or a WebService.
http://examples2.ext.net/#/GridPanel/Paging_and_Sorting/Handler/

Personally, I would definitely prefer the option #2 or #3.