PDA

View Full Version : [CLOSED] Get Item from Store



osef
Oct 01, 2013, 12:33 AM

Daniil
Oct 01, 2013, 4:42 AM
Hi @osef,

A selected item is submitted automatically if there is a <form runat="server"> on the page. So, you can get it this way:

this.MultiSelectID.SelectedItem.Value

As for the first item. It is not submitted. You can retrieve it on client side and send as an extra parameter of a request.

App.MultiSelectId.getStore().getAt(0).data[App.MultiSelectId.valueField]

osef
Oct 01, 2013, 5:43 AM
Hi @osef,

A selected item is submitted automatically if there is a <form runat="server"> on the page. So, you can get it this way:

this.MultiSelectID.SelectedItem.Value

As for the first item. It is not submitted. You can retrieve it on client side and send as an extra parameter of a request.

App.MultiSelectId.getStore().getAt(0).data[App.MultiSelectId.valueField]

Hi Daniil, thank you, but, How Can I to get the full object("Art") from of Store?

Exameple: Art objArt = (Art)StoreID...;

My Store is DataBind with a List<Art>.

Regards

Daniil
Oct 01, 2013, 8:21 AM
You can submit a Store's data.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
public class Test
{
public string Value { get; set; }
public string Text { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.MultiSelect1.GetStore();
store.DataSource = new object[]
{
new Test()
{
Value = "1",
Text = "Item 1"
},
new Test()
{
Value = "2",
Text = "Item 2"
},
new Test()
{
Value = "3",
Text = "Item 3"
}
};
}
}

protected void Submit(object sender, DirectEventArgs e)
{
List<Test> tests = JSON.Deserialize<List<Test>>(e.ExtraParams["data"]);

X.Msg.Alert("Submit", tests.Count).Show();
}
</script>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:MultiSelect
ID="MultiSelect1"
runat="server"
ValueField="Value"
DisplayField="Text">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Value" />
<ext:ModelField Name="Text" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:MultiSelect>

<ext:Button runat="server" Text="Submit">
<DirectEvents>
<Click OnEvent="Submit">
<ExtraParams>
<ext:Parameter
Name="data"
Value="App.MultiSelect1.getStore().getRecordsValues()"
Mode="Raw"
Encode="true" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
</form>
</body>
</html>

osef
Oct 01, 2013, 10:07 PM

Daniil
Oct 02, 2013, 6:15 AM
Misunderstood the requirement. Here is a new example.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
public class Test
{
public string Value { get; set; }
public string Text { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.MultiSelect1.GetStore();
store.DataSource = new object[]
{
new Test()
{
Value = "1",
Text = "Item 1"
},
new Test()
{
Value = "2",
Text = "Item 2"
},
new Test()
{
Value = "3",
Text = "Item 3"
}
};
}
}

protected void Submit(object sender, DirectEventArgs e)
{
Test selectedItem = JSON.Deserialize<Test>(e.ExtraParams["data"]);

X.Msg.Alert("Submit", selectedItem.Text).Show();
}
</script>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>

<script>
var getSelectedData = function () {
var s = App.MultiSelect1.getSelected();

if (s.length > 0) {
s = s[0].data;
}

return Ext.encode(s);
};
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:MultiSelect
ID="MultiSelect1"
runat="server"
ValueField="Value"
DisplayField="Text"
SingleSelect="true">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Value" />
<ext:ModelField Name="Text" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:MultiSelect>

<ext:Button runat="server" Text="Submit">
<DirectEvents>
<Click OnEvent="Submit" Before="return App.MultiSelect1.getSelected().length > 0;">
<ExtraParams>
<ext:Parameter
Name="data"
Value="getSelectedData()"
Mode="Raw" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
</form>
</body>
</html>


I see the method "getRecordsValues()" is not in extjs 4.2.2 docs, Is this a new method?

This method appeared in Ext.NET, not in ExtJS.

osef
Oct 03, 2013, 6:03 AM
Thank you Daniil, this is working, It only one thing, where is the docs of that method (getRecordsValues())?, because the server methods are here (http://docs.ext.net).

Daniil
Oct 03, 2013, 6:12 AM
Unfortunately, we have no docs for client side part of Ext.NET.

osef
Oct 03, 2013, 4:52 PM
Unfortunately, we have no docs for client side part of Ext.NET.

Thank you, you can to close this thread.