PDA

View Full Version : [CLOSED] how can I get GridFilters NumericFilter value on code behind?



cottimucin
Aug 12, 2014, 2:14 PM
how can I get GridFilters NumericFilter value on code behind?




<Features>
<ext:GridFilters runat="server" ID="GridFilters1" Local="true">
<Filters>
<ext:StringFilter DataIndex="C1"/>
<ext:NumericFilter DataIndex="C2"></ext:NumericFilter>
</Filters>
</ext:GridFilters>
</Features>


How can I get C1 and C2 value on code behind? And I need filter is active or not ?

I can set numeric filter same as this.

NumericFilter sf = (NumericFilter)GridFilters1.Filters[1];
sf.SetValue(1211);
sf.SetActive(true);


but I cant get value of filter! and filter is active?


NumericFilter nf = (NumericFilter)GridFilters1.Filters[1];
string hoca = nf.GetValue.ToString();

Daniil
Aug 12, 2014, 3:26 PM
Hi @cottimucin,

The only way is to send those values from client to server as extra parameters of a request.

cottimucin
Aug 12, 2014, 3:40 PM
thank you daniil

cottimucin
Aug 13, 2014, 6:36 AM
how can I get value of filter and filter is active? on server side?

Daniil
Aug 13, 2014, 10:08 AM
Do you mean on client side?

cottimucin
Aug 13, 2014, 10:45 AM
thank you daniil
I solved my problem with another way

Daniil
Aug 13, 2014, 2:28 PM
Sharing a solution might help others who finds this thread in the future.

cottimucin
Aug 14, 2014, 7:25 AM
I used a textbox for filter and I set the filter same as below
so that I dont need getvalue of filter.



NumericFilter sf = (NumericFilter)GridFilters1.Filters[1];
sf.SetValue(Convert.ToInt32(filter1.Text));
sf.SetActive(true);

Daniil
Aug 14, 2014, 3:49 PM
Please clarify does it mean that the problem has been resolved?

cottimucin
Aug 15, 2014, 7:06 AM
problem has not been resolved?
but I solved my problem with this way.

if I can get value of filter. I will be very glad.

Daniil
Aug 15, 2014, 10:47 AM
Please clarify have you tried this?

The only way is to send those values from client to server as extra parameters of a request.

Also could you, please, clarify why you need a filter value on server? Do you want to filter the data on server side? If so, please look at this example.
http://examples2.ext.net/#/GridPanel/Plugins/GridFilters_Remote/

cottimucin
Aug 15, 2014, 12:13 PM
Remote filter using sample is;

e.Parameters[this.GridFilters1.ParamPrefix]; using with "Store1_RefreshData(object sender, StoreReadDataEventArgs e)"




protected void Store1_RefreshData(object sender, StoreReadDataEventArgs e)
{
List<object> data = FiltersTestData.Data;

string s = e.Parameters[this.GridFilters1.ParamPrefix];
//or with hardcoding - string s = e.Parameters["filter"];
}






can I do this under ext:button click event ?

same as below
how can I do this ?



protected void exportToPdf(object sender, DirectEventArgs e)
{
//GridPanel is named MitigationCategories
//GridFilters is named filterGrid and contains 1 StringFilter against a DataIndex="FE".
//I would like to be able to determine if the the FE filter is active and if so what its value is.
}

Daniil
Aug 15, 2014, 3:38 PM
This way:

<ext:Button runat="server" Text="Export To pdf">
<DirectEvents>
<Click OnEvent="ExportToPdf">
<ExtraParams>
<ext:Parameter
Name="gridFilters"
Value="App.GridPanel1.getFilterPlugin().buildQuery(App.Gr idPanel1.getFilterPlugin().getFilterData())"
Mode="Raw"
Encode="true"
/>
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>

protected void ExportToPdf(object sender, DirectEventArgs e)
{
string s = e.ExtraParams["gridFilters"];
}

cottimucin
Aug 18, 2014, 6:42 AM
Hi Daniil,

I do this



<ext:Button ID="Button3" runat="server" Icon="Printer" Text="Yazdır">
<DirectEvents>
<Click OnEvent="yazdir">

<ExtraParams>
<ext:Parameter Name="gridFilters" Value="#{GridPanel1}.getFilterPlugin().buildQuery(#{GridP anel1}.getFilterPlugin().getFilterData())" Mode="Raw" Encode="true" />
</ExtraParams>

</Click>
</DirectEvents>
</ext:Button>





protected void yazdir(object sender, DirectEventArgs e)
{

string s = e.ExtraParams["gridFilters"];


//-- start filtering ------------------------------------------------------------
if (!string.IsNullOrEmpty(s))
{
FilterConditions fc = new FilterConditions(s);

foreach (FilterCondition condition in fc.Conditions)
{
Comparison comparison = condition.Comparison;
string field = condition.Field;
FilterType type = condition.Type;

object value;
switch (condition.Type)
{
case FilterType.Boolean:
value = condition.Value<bool>();
break;
case FilterType.Date:
value = condition.Value<DateTime>();
break;
case FilterType.List:
value = condition.List;
break;
case FilterType.Numeric:
value = condition.Value<int>();
break;
case FilterType.String:
value = condition.Value<string>();
break;
default:
throw new ArgumentOutOfRangeException();
}

}
}
}



I get error message belove;

14541

Daniil
Aug 18, 2014, 3:14 PM
What is the content of the "s" variable when the Exception is thrown?

Could you, please, provide a full test case?

cottimucin
Aug 19, 2014, 7:13 AM
content of the "s" variable when the Exception is thrown



"{\"filter\":\"[{\\\"type\\\":\\\"string\\\",\\\"value\\\":\\\"08107\\\",\\\"field\\\":\\\"KODU\\\"},{\\\"type\\\":\\\"numeric\\\",\\\"comparison\\\":\\\"eq\\\",\\\"value\\\":3247,\\\"field\\\":\\\"OGRELEMANIKODU\\\"}]\"}"






button



<ext:Button ID="Button3" runat="server" Icon="Printer" Text="Yazdır">
<DirectEvents>
<Click OnEvent="yazdir">

<ExtraParams>
<ext:Parameter Name="gridFilters" Value="#{GridPanel1}.getFilterPlugin().buildQuery(#{GridP anel1}.getFilterPlugin().getFilterData())" Mode="Raw" Encode="true" />
</ExtraParams>

</Click>
</DirectEvents>
</ext:Button>


protected void yazdir(object sender, DirectEventArgs e)
{

string s = e.ExtraParams["gridFilters"];


//-- start filtering ------------------------------------------------------------
if (!string.IsNullOrEmpty(s))
{
FilterConditions fc = new FilterConditions(s);

foreach (FilterCondition condition in fc.Conditions)
{
Comparison comparison = condition.Comparison;
string field = condition.Field;
FilterType type = condition.Type;

object value;
switch (condition.Type)
{
case FilterType.Boolean:
value = condition.Value<bool>();
break;
case FilterType.Date:
value = condition.Value<DateTime>();
break;
case FilterType.List:
value = condition.List;
break;
case FilterType.Numeric:
value = condition.Value<int>();
break;
case FilterType.String:
value = condition.Value<string>();
break;
default:
throw new ArgumentOutOfRangeException();
}

}
}





gridfilter




<Features>
<ext:GridFilters runat="server" ID="GridFilters1" Local="true">
<Filters>
<ext:StringFilter DataIndex="KODU"/>
<ext:NumericFilter DataIndex="OGRELEMANIKODU"></ext:NumericFilter>
</Filters>
</ext:GridFilters>
</Features>

Daniil
Aug 19, 2014, 11:12 AM
Please try the following.

Replace

Value="#{GridPanel1}.getFilterPlugin().buildQuery(#{GridP anel1}.getFilterPlugin().getFilterData())"

with

Value="#{GridPanel1}.getFilterPlugin().buildQuery(#{GridP anel1}.getFilterPlugin().getFilterData()).filter"
and remove Encode-"true".

cottimucin
Aug 19, 2014, 11:54 AM
thanks daniil everything is all right.