Mar 27, 2014, 10:14 AM
[CLOSED] How to reload a combobox column store depending of the row id ?
Hi,
I have a GridPanel with a Combobox Colum (Component Column) and i need to relaod the store of the combobox, each time i move from a row to another.
The values of the store must be filled by a field of the record associated with the row !
Unfortunately the Store is filled once and but keep the same content from row to row.
Here is my code:
EditPAge.aspx:
I have a GridPanel with a Combobox Colum (Component Column) and i need to relaod the store of the combobox, each time i move from a row to another.
The values of the store must be filled by a field of the record associated with the row !
Unfortunately the Store is filled once and but keep the same content from row to row.
Here is my code:
EditPAge.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditablePage.aspx.cs" Inherits="NTECH.Training.Ui.Web.EditablePage" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script type="text/javascript">
var Before = function (item,e) {
if (e.record.data.editable == false)
{
if (e.field == "test1") return false;
if (e.field == "test2") return false;
}
return true;
};
var EditJS = function (id, coche, champ, inclus, exclus)
{
var toto = id;
if (coche) {
if (inclus != null) {
for (i = 0; i < inclus.length; i++) {
App.Store1.getById(inclus[i].Id).set("editable", true);
}
}
if (exclus != null) {
for (j = 0; j < exclus.length; j++) {
App.Store1.getById(exclus[j].Id).set("editable", false);
}
}
}
}
</script>
<!DOCTYPE html>
<html><head id="Head1" runat="server">
<title>Ext.NET v2 Example</title></head>
<body> <form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" DirectMethodNamespace="NSIA" ShowWarningOnAjaxFailure="false" />
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model ID="Model1" runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="ID" ServerMapping="ID"/>
<ext:ModelField Name="test1" ServerMapping="Text1"/>
<ext:ModelField Name="test2" ServerMapping="Text2"/>
<ext:ModelField Name="editable" ServerMapping="Flag" />
<ext:ModelField Name="Choix" Type="int" />
<ext:ModelField Name="inclus" ServerMapping="Inclus" Type="Auto"/>
<ext:ModelField Name="exclus" ServerMapping="Exclus" Type="Auto"/>
<ext:ModelField Name="Franchise" ServerMapping="Franchise" Type="int"/>
</Fields>
</ext:Model>
</Model>
</ext:Store>
<ext:Store ID="FranchiseStore" runat="server" AutoDataBind="true">
<Model>
<ext:Model ID="Model2" runat="server" IDProperty="Id">
<Fields>
<ext:ModelField Name="Id" Type="int" ServerMapping="Id"/>
<%--<ext:ModelField Name="Libelle" Type="int" ServerMapping="Id" />--%>
</Fields>
</ext:Model>
</Model>
</ext:Store>
<ext:GridPanel ID="GridPanel1" runat="server" StoreID="Store1">
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ID="Column3" runat="server" Text="Identifiant" DataIndex="ID" Locked="true">
</ext:Column>
<ext:Column ID="Column1" runat="server" Text="Test 1" DataIndex="test1" Visible="false">
<Editor>
<ext:TextField ID="TextField1" runat="server" />
</Editor>
</ext:Column>
<ext:Column ID="Column2" runat="server" Text="Test 2" DataIndex="test2" Visible="false">
<Editor>
<ext:TextField ID="TextField2" runat="server" />
</Editor>
</ext:Column>
<ext:CheckColumn ID="CheckColumn1" runat="server" DataIndex="editable" Editable="true" />
</Columns>
</ColumnModel>
<Plugins>
<ext:CellEditing ID="CellEditing1" runat="server" >
<Listeners>
<BeforeEdit Handler="return Before(item,e);" />
<Edit Handler="EditJS(e.record.data.ID,e.record.data.editable,e.field,e.record.data.inclus,e.record.data.exclus);" />
<%--<Edit Handler="return NSIA.GetEdit(e.record.data.ID,e.record.data.editable,e.field,Ext.encode(#{GridPanel1}.getRowsValues({selectedOnly:false})));" /> --%>
</Listeners>
</ext:CellEditing>
</Plugins>
</ext:GridPanel>
<hr />
<ext:GridPanel ID="GridPanel2" runat="server" StoreID="Store1">
<ColumnModel ID="ColumnModel2" runat="server" Visible="true">
<Columns>
<ext:Column ID="Column4" runat="server" Text="Identifiant" DataIndex="ID" Locked="true">
</ext:Column>
<ext:Column ID="Column5" runat="server" Text="Test 1" DataIndex="test1">
<Editor>
<ext:TextField ID="TextField3" runat="server" />
</Editor>
</ext:Column>
<ext:Column ID="Column6" runat="server" Text="Test 2" DataIndex="test2">
<Editor>
<ext:TextField ID="TextField4" runat="server" />
</Editor>
</ext:Column>
<ext:ComponentColumn ID="ComponentColumn1"
runat="server"
Editor="true"
DataIndex="Franchise"
Flex="1"
Text="Franchise">
<Component>
<ext:ComboBox ID="ComboBox1" runat="server" StoreID="FranchiseStore" DisplayField="Id" ValueField="Id" Width="100">
</ext:ComboBox>
</Component>
</ext:ComponentColumn>
</Columns>
</ColumnModel>
<Plugins>
<ext:CellEditing ID="CellEditing2" runat="server" >
<Listeners>
<BeforeEdit Handler="return true;" />
<%--<ValidateEdit Handler="return NSIA.GetEdit(e.record.data.ID,e.record.data.editable,e.field,Ext.encode(#{GridPanel1}.getRowsValues({selectedOnly:false})));" />--%>
</Listeners>
</ext:CellEditing>
</Plugins>
<%-- <Listeners>
<SelectionChange Handler="NSIA.DataStore(0,Ext.encode(#{GridPanel2}.getRowsValues({selectedOnly: true})))"></SelectionChange>
</Listeners>--%>
<View>
<ext:GridView ID="GridView1" runat="server">
<GetRowClass Handler="if(record.data.editable == false){return 'x-hidden';}" />
</ext:GridView>
</View>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server">
<DirectEvents>
<Select OnEvent="Unnamed_Event">
<ExtraParams>
<ext:Parameter Name="ID" Value="record.data.ID" Mode="Raw" />
<ext:Parameter Name="inclus" Value="record.data.inclus" Mode="Raw" />
</ExtraParams>
</Select>
</DirectEvents>
</ext:RowSelectionModel>
</SelectionModel>
</ext:GridPanel>
</form>
</body>
</html>
EditPage.aspx.csusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
namespace NTECH.Training.Ui.Web
{
public partial class EditablePage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.GridPanel1.GetStore();
TestObject[] source = new TestObject[]
{
new TestObject()
{ ID=1, Text1 = "test1", Text2 = "test1", Flag = false , Exclus = new Enfant[]{new Enfant(2),new Enfant(4)}, Inclus = new Enfant[]{new Enfant(3),new Enfant(5),new Enfant(6)}},
new TestObject()
{ ID=2, Text1 = "test2", Text2 = "test2", Flag = false },
new TestObject()
{ID=3, Text1 = "test3", Text2 = "test3", Flag = false },
new TestObject()
{ ID=4, Text1 = "test1", Text2 = "test1", Flag = false , Exclus = new Enfant[]{new Enfant(3),new Enfant(5)}, Inclus = new Enfant[]{new Enfant(2),new Enfant(6)}},
new TestObject()
{ ID=5, Text1 = "test2", Text2 = "test2", Flag = false },
new TestObject()
{ID=6, Text1 = "test3", Text2 = "test3", Flag = false }
};
store.DataSource = source;
Session["Datas" + System.Environment.MachineName] = source;
}
}
[DirectMethod]
public bool GetEdit(string recordID,string coche, string field, string param)
{
List<TestObject> liste = new List<TestObject>();
int id = int.Parse(recordID);
TestObject[] liste2 = Session["Datas" + System.Environment.MachineName] as TestObject[];
TestObject to2 = liste2.Where(t => t.ID == id).FirstOrDefault();
int[] inclus = to2.Inclus != null ? to2.Inclus.Select(c=>c.Id).ToArray() : null;
int[] exclus = to2.Exclus != null ? to2.Exclus.Select(c => c.Id).ToArray() : null;
try
{
//string jsonValues = param;
//List<Dictionary<string, string>> records = JSON.Deserialize<List<Dictionary<string, string>>>(jsonValues);
//foreach(var record in records)
//{
// TestObject to = new TestObject();
// to.ID = int.Parse(record["ID"]);
// to.Text1 = record["test1"];
// to.Text2 = record["test2"];
// //if (field == "editable" && to.Text1 != recordID)
// // to.Flag = !bool.Parse(record["editable"]);
// //else
// if (inclus != null && inclus.Contains(to.ID))
// to.Flag = true;
// else if (exclus != null && exclus.Contains(to.ID))
// to.Flag = false;
// else
// to.Flag = bool.Parse(record["editable"]);
// if (to.ID == id)
// {
// to.Inclus = inclus;
// to.Exclus = exclus;
// }
// liste.Add(to);
// Store store = GridPanel1.Store[0];
if (coche == "true")
{
if (inclus != null)
{
foreach (int i in inclus)
Store1.GetById(i).Set("editable", true);
}
if (exclus != null)
{
foreach (int j in exclus)
Store1.GetById(j).Set("editable", false);
}
}
}
catch (Exception err)
{ //throw;
}
return true;
}
protected void TypeBeneficiaireStore_ReadData(object sender, StoreReadDataEventArgs e)
{
}
[DirectMethod]
public void DataStore(object id, object variable)
{
object i = id;
Newtonsoft.Json.Linq.JContainer jsonValues = variable as Newtonsoft.Json.Linq.JContainer;
object val = jsonValues.Value<TestObject>(0);
//foreach (var record in records)
//{
// string inclus = record["inclus"];
// break;
//}
}
protected void FranchiseStore_ReadData(object sender, StoreReadDataEventArgs e)
{
int i = 0;
//FranchiseStore.DataSource;
}
protected void Unnamed_Event(object Sender, DirectEventArgs e)
{
string ID = e.ExtraParams["ID"];
int id = int.Parse(ID);
TestObject[] source = Session["Datas" + System.Environment.MachineName] as TestObject[];
TestObject to = source.Where(c => c.ID == id).FirstOrDefault();
if (to != null && to.Inclus != null)
{
FranchiseStore.DataSource = to.Inclus;
FranchiseStore.DataBind();
}
else
FranchiseStore.RemoveAll();
}
}
public class TestObject
{
public string Text1 { set; get; }
public string Text2 { set; get; }
public bool Flag { set; get; }
public int ID { set; get; }
public Enfant[] Exclus { set; get; }
public Enfant[] Inclus { set; get; }
public int Franchise { set; get; }
}
public class Enfant
{
public int Id { set; get; }
public Enfant(int id) { Id = id; }
public override string ToString()
{
return Id.ToString();
}
}
}
Last edited by Daniil; Apr 03, 2014 at 4:10 AM.
Reason: [CLOSED]