PDA

View Full Version : [CLOSED] ext:GridPanel. I need a listener that occurs before the Json webservice is invoked.



supera
Apr 03, 2012, 2:04 PM
Hi!

In my ext:Store, I trying call a DirectMethod (in another aspx page within another panel) that return a filter for my query.

I'm using a listener BeforeLoad, but, this listener occurs when the data are returned and will be loading in gridPanel (appears to me).

What listener of ext:Store or ext:GridPanel I can use to do this?



<Listeners>
<BeforeLoad Handler="if(parent.X.getCmp('panelFilter') != undefined){parent.App.panelFilter.getBody().App.di rect.GetFilter({success: function(result){App.txtExternalFilter.setValue(re sult);}});};" />
</Listeners>

Daniil
Apr 03, 2012, 2:36 PM
Hi,

A load request doesn't wait then a DirectMethod will be executed. I.e. it calls a DirectMethod, then immediately makes a load request.

At the first of all I would try to find a possibility to avoid such design.

What actions do you call within the GetFilter DirectMethod? Can't they be performed client side?

supera
Apr 03, 2012, 4:04 PM
Hi Daniil!



What actions do you call within the GetFilter DirectMethod? Can't they be performed client side?


1 - I have a main page with two ext:Panels called panelFilter and panelData.
2 - In panelFilter, I'm loading a aspx page (with loader of panel) with fields to set any params of filter to query loaded in panelData.
3 - In panelData, I'm loading a gridPanel with data returned by Json webservice. The data loaded in gridPanel are dynamic, defined in a parameter of Json Webservice and depends of context.
4 - The page loaded in panelFilter depends of the data loaded in panelData. If I load the Customers data in gridPanel in panelData, the panelFilter is loaded with a page that contains ext:TextFields and ComboBox to make a SQL WHERE statement to this context (Customer).

Summarizing:
The page loaded into panelFilter may vary depending on the context, and only the common access point of page within panelData to your filter is the directmethod getFilter. Diferent filter pages are implements this directmethod, returning a SQL Where Statment (or part of this).

The way I found to be several pages of filter depending on the context (Customer, Supplier, Products) is this. But I'm open to suggestions.

I do not know how to do on client side this. The page loaded in panelData donīt know the details of page loaded in panelFilter. The page loaded in panelFilter should return to page loaded in panelData the sql where statment...

Sorry about my difficult in express what I need. Thanks a lot for any help.

Daniil
Apr 03, 2012, 6:04 PM
Thanks for the details.

Could you also demonstrate the code of the GetFilter method?

supera
Apr 03, 2012, 6:17 PM
Well... is a very simple code...

The getFilter of CustomerFilter.aspx is:


<DirectMethod()>
Public Function GetFilter() As String
Dim sFilter As String = ""

If txtCity.Text <> "" Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "(City like '" & txtCity.Text & "')"
End If

If txtProfession.Text <> "" Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "(Profession like '" & txtProfession.Text & "')"
End If

If IsDate(dtStart.SelectedDate) And IsDate(dtEnd.SelectedDate) Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "([CreatedIn] between convert(smalldatetime,'" & Format(dtStart.SelectedDate, "dd/MM/yyyy") & " 00:00',103) and convert(smalldatetime,'" & Format(dtEnd.SelectedDate, "dd/MM/yyyy") & " 23:59',103))"
End If

If cmbStatus.SelectedItem.Value <> "-1" Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "(Status = " & cmbStatus.SelectedItem.Value & ")"
End If

Return sFilter


The directmethod getFilter of TaskFilter.aspx is :


<DirectMethod()>
Public Function GetFilter() As String
Dim sFilter As String = ""

If txtCriador.Text <> "" Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "(Criador like '" & txtCriador.Text & "')"
End If

If txtExecutor.Text <> "" Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "(Executor like '%" & txtExecutor.Text & "%')"
End If

If txtEmpresa.Text <> "" Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "(Cliente like '" & txtEmpresa.Text & "')"
End If

If txtFornecedor.Text <> "" Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "(Fornecedor like '" & txtFornecedor.Text & "')"
End If

If txtOrigem.Text <> "" Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "(Origem like '" & txtOrigem.Text & "')"
End If

Select Case cmbPeriodo.SelectedItem.Value.ToUpper.Trim
Case "0"
Case "1"
If (IsDate(dtIni.SelectedDate) And IsDate(dtFim.SelectedDate)) AndAlso ((dtIni.SelectedDate <> #12:00:00 AM#) And (dtFim.SelectedDate <> #12:00:00 AM#)) Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "([Prazo Inicial] between convert(smalldatetime,'" & Format(dtIni.SelectedDate, "dd/MM/yyyy") & " 00:00',103) and convert(smalldatetime,'" & Format(dtFim.SelectedDate, "dd/MM/yyyy") & " 23:59',103))"
End If
Case "2"
If IsDate(dtIni.SelectedDate) And IsDate(dtFim.SelectedDate) AndAlso ((dtIni.SelectedDate <> #12:00:00 AM#) And (dtFim.SelectedDate <> #12:00:00 AM#)) Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "([Prazo Final] between convert(smalldatetime,'" & Format(dtIni.SelectedDate, "dd/MM/yyyy") & " 00:00',103) and convert(smalldatetime,'" & Format(dtFim.SelectedDate, "dd/MM/yyyy") & " 23:59',103))"
End If
End Select

If cmbPrioridade.SelectedItem.Value <> "-1" Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "(Prioridade = " & cmbPrioridade.SelectedItem.Value & ")"
End If

If cmbStatus.SelectedItem.Value <> "-1" Then
sFilter = sFilter & IIf(sFilter <> "", " AND ", "") & "(Status = " & cmbStatus.SelectedItem.Value & ")"
End If

Return sFilter

End Function


I will make many other filter, depending the context (data loaded in my gridPanel)...

Daniil
Apr 03, 2012, 6:37 PM
Seems, it's all might be implemented via JavaScript.

I would implement it via JavaScript in the Filter page and call a JavaScript function instead of a DirectMethod.

What about to port it to JavaScript? We strongly recommend to implement in JavaScript as much as possible. We would assist if you will be in trouble.

Regarding to your initial request.

You could return false from a BeforeLoad listener to prevent a load request. Then in a "success" handler you can call the Store reload function.

Also you will need to lock a BeforeLoad listener from executing for calling reload function within a "success" DirectMethod handler.

Something like this:

store.locked = true;
store.reload();
store.locked = false;

And place

if (!store.locked) {
// the BeforeLoad listener code
}
at the beginning of the BeforeLoad listener.

But, repeat myself, I would port the GetFilter code to JavaScript.

supera
Apr 03, 2012, 6:42 PM
Hi Daniil!

Thanks a lot for your help!

I would like try your approach (port to Javascript)...

Where do we begin?

Daniil
Apr 03, 2012, 7:40 PM
Well, porting the GetFilter to JavaScript step by step.

Could you clarify where exactly are you in trouble?

supera
Apr 03, 2012, 7:54 PM
How I call the Javascript function getFilter in CustomerFilter.aspx (page contained in panelFilter)?

In directmethod I do this:

1 - Check if my parent page has a panel called panelFilter...
2- Call the directMethod getFilter in page within panelFilter



if(parent.X.getCmp('panelFilter') != undefined){parent.App.panelFilter.getBody().App.di rect.GetFilter({success: function(result){alert(result);}});};


I think that I need do:
1 - Create in CustomerFilter.aspx, TaskFilter.aspx, etc a Javascript method called getFilter.
2 - Call this Javascript function in my page that contains the gridPanel.

But I don't know how I call the javascript function in aspx page contained in panelFilter.

Daniil
Apr 03, 2012, 8:11 PM
Generally, the same way:

parent.App.panelFilter.getBody().javaScriptFunctio nName()

supera
Apr 04, 2012, 11:48 AM
Hi Daniil!

Sorry for my little knowledge in Javascript.

Your suggestion works very fine!

Thanks a lot!

Daniil
Apr 04, 2012, 11:49 AM
No problem.

Can we mark the thread as closed?

supera
Apr 04, 2012, 11:55 AM
Yes, you can...