PDA

View Full Version : Why event rowdlbclick is called when grid is being created?



Stargazers
2 Jul 2008, 12:13 AM
I have added event:


wtTable.on( 'rowdblclick', addInformationTab() );


But everytime when I refresh my web browser, it calls that method? Why?

Animal
2 Jul 2008, 12:14 AM
What does the statement



addInformationTab()


do?

Stargazers
2 Jul 2008, 12:17 AM
It is my function, what is defined later:



function addInformationTab()
{
alert( 'Testing...' );
}


At this point nothing more. Everytime when I press f5, it displays Testing... information before the grid is displayed.

Animal
2 Jul 2008, 12:58 AM
Please answer the question. It will help if you consider it.

What does the statement



addInformationTab()


do?

Stargazers
2 Jul 2008, 1:02 AM
What do you mean if you don't mean that what I answerred? It is in this line:

wtTable.on( 'rowdblclick', addInformationTab() );
because it is meant that when user double clicks row, the it should call that function, called addInformationTab(), but everytime when grid loads that addInformationTab function is called also? And I have pasted that all what is does at this point is just plain alert.

Animal
2 Jul 2008, 1:05 AM
One more try.

What, on a basic overview level does the statement



myFunction()


actually do. In overall Javascript terms.

Stargazers
2 Jul 2008, 1:14 AM
One more try.

What, on a basic overview level does the statement



myFunction()
actually do. In overall Javascript terms.


Well, as I said: it does nothing more than just plain alert. Nothing less, nothing more.

In the future I am going to add code that opens a new tab to my tab panel (that is why it is named like that), but I have noticed that it calls that dblclick method even when grid is loading, so I have to know why so I can make it work 'right' before I'm going to add more code to that function.

Animal
2 Jul 2008, 1:57 AM
Oh for god's sake!



myFunction()


CALLS the function "myFunction"

That's all!

So, you are CALLING your function. SO of course it runs!!!

WHy can't you just consider what you are asked to consider?

Your function runs because you call it!

Stargazers
2 Jul 2008, 2:00 AM
What?

I have said that why Ext call this function even before the grid is shown? And yes, of course it calls that function when I doubleclick the row, but why it calls that function even before the grid is shown? That was the question, not why it calls that function when I call it. It calls it even I don't call it (before the grid is shown)! That is the problem.

Animal
2 Jul 2008, 2:03 AM
BECAUSE YOU CALL IT BEFORE THE GRID IS SHOWN!

What does the statement



addInformationTab()



do?

Answer: IT CALLS THE FUNCTION!

Stargazers
2 Jul 2008, 2:10 AM
No?

Well, maybe I have misunderstood what you meant and you have misunderstood what I meant.
So let's explain it again.

So: I have EditorGridPanel wtTable. Then I add this code:


wtTable.on( 'rowdblclick', addInformationTab() );
Then when I doubleclick row, it calls my function addInformationTab as it should, and it is this kind:



function addInformationTab()
{
alert( 'Testing...' );
}
So, when I load my page it shows information "Testing..." even before the grid is shown, so I can't be double clicked that grid. So the problem is, WHY it calls addInformationTab even on page reload even that it is called ONLY in that rowdblclick function?

So it seems that ext (or something other) fires rowdblclick event even on page load.

Was that more clear?

Animal
2 Jul 2008, 2:12 AM
No?

Well, maybe I have misunderstood what you meant and you have misunderstood what I meant.
So let's explain it again.

So: I have EditorGridPanel wtTable. Then I add this code:


wtTable.on( 'rowdblclick', addInformationTab() );


Right!

That code contains A CALL to your function

Stargazers
2 Jul 2008, 2:14 AM
Well, there is now possibility to add listener what fires on double click and only in double click, not on page load also?

Starfall
2 Jul 2008, 2:20 AM
Animal, let me try :)

Stargazers, let's consider statement

wtTable.on( 'rowdblclick', addInformationTab() );What happens when the JS Interpreter in browser executes this line (in mean terms)?

It figures out the value wtTable variable - looks like it's a grid object.
Tries to call method on of object wtTable - this method exists and all is well
Figures out the arguments passed to the on method - the value of argument is the value that is returned after execution of the statement in arguments list.
First argument is a string - being "executed", it returns itself.
Second argument is, in your code, a function call, not a function. So, executing addInformationTab() leads to execution of function addInformationTab, which leads to displaying alert. See, alert happens before the rowdblclick because of the execution of function itself.Change addInformationTab() to addInformationTab. This way you pass the function itself as an argument.

Stargazers
2 Jul 2008, 2:23 AM
Thank you very much, Starfall!
Your answer was so clear and that totally makes sense and now it works perfectly.
Thank you!

30 Jul 2008, 2:57 PM
Could you not simply let the fellow know that he was actually executing the function in the statement


wtTable.on( 'rowdblclick', addInformationTab() );

and perhaps just did not realize that he was not passing the "POINTER" to the function as perhaps he really meant to, such as


wtTable.on( 'rowdblclick', addInformationTab );

I guess what I am getting at here, is that I don't understand the harsh replies to such a very simple question, and perhaps something the individual simply overlooked. I know I have mistakenly done similar things and just didn't notice until someone pointed it out to me.

Go a little easy ... jeez...