Re: Calling Javascript for any event in a parent
Hi! You can override #onEvent in your “parent” component. The AjaxRequestTarget is broadcast as an event (you can check if the payload is an ART). You can then check if the ART contains your table component, and if it does, append your javascript. Met vriendelijke groet, Kind regards, Bas Gooren Op 22 december 2016 bij 15:40:23, MissOvenMitts ( chantal.lucette.da...@gmail.com) schreef: Thank you guys so much for your quick responses! I had not tried global listeners - mostly because if I have a component and not a target (as one of the method parameters) I don't really get how to call a javascript function. For example, when I have a target, I can do a target.appendJavaScript() target.appendJavaScript("alert('You clicked a button!')"); br/> < ... and that runs immediately. I guess with this example I'm not sure where to put the javascript, is my point. So, for more detail on what I'm trying to do: It is, in fact, the same exact Javascript that needs to be run for every button/link in the data table (in addition to the function the buttons already perform, obviously, like paging). At the moment I have a behavior attached to a random WebMarkupContainer on the base page where the datatable is (the datatable is not a child of the WebMarkupContainer.. this is just the only way I really know how to add javascript into the header and into the onDomReady). br/> < This behavior simply renders javascript to the header for the javascript function that I want to use called myTableFunction. Then the behavior simply adds the following javascript on Dom Ready: ("$(\"html\").find(\".mySpecialTableClass\").myTableFunction({'left' : 1, 'foot' : true, 'head' : true});"); This javascript just searches the page for a particular class and runs a javascript function on it. The javascript doesn't need the wicket's Component ID, and the behavior that creates the javascript isn't even attached to the wicket table which receives the changes from the javascript. So, as it stands, the javascript function is called when the page loads up and everything works perfectly. However, obviously, whenever any paging links in the .mySpecialTableClass data-table are clicked, the table is refreshed and the changes that the javascript myTableFunction() made on the table naturally disappear. br/> < As a result, we want to tack the same javascript we already put onDomReady onto any other clicks within the data table that might refresh it. I hope that makes more sense! Again, your help is so appreciated. This has been one of those changes that has you pacing outside wanting to tear your hair out. It's *so* close to completion that it's that much more frustrating. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Calling-Javascript-for-any-event-in-a-parent-tp4676501p4676510.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Calling Javascript for any event in a parent
Thank you guys so much for your quick responses! I had not tried global listeners - mostly because if I have a component and not a target (as one of the method parameters) I don't really get how to call a javascript function. For example, when I have a target, I can do a target.appendJavaScript() target.appendJavaScript("alert('You clicked a button!')"); ... and that runs immediately. I guess with this example I'm not sure where to put the javascript, is my point. So, for more detail on what I'm trying to do: It is, in fact, the same exact Javascript that needs to be run for every button/link in the data table (in addition to the function the buttons already perform, obviously, like paging). At the moment I have a behavior attached to a random WebMarkupContainer on the base page where the datatable is (the datatable is not a child of the WebMarkupContainer.. this is just the only way I really know how to add javascript into the header and into the onDomReady). This behavior simply renders javascript to the header for the javascript function that I want to use called myTableFunction. Then the behavior simply adds the following javascript on Dom Ready: ("$(\"html\").find(\".mySpecialTableClass\").myTableFunction({'left' : 1, 'foot' : true, 'head' : true});"); This javascript just searches the page for a particular class and runs a javascript function on it. The javascript doesn't need the wicket's Component ID, and the behavior that creates the javascript isn't even attached to the wicket table which receives the changes from the javascript. So, as it stands, the javascript function is called when the page loads up and everything works perfectly. However, obviously, whenever any paging links in the .mySpecialTableClass data-table are clicked, the table is refreshed and the changes that the javascript myTableFunction() made on the table naturally disappear. As a result, we want to tack the same javascript we already put onDomReady onto any other clicks within the data table that might refresh it. I hope that makes more sense! Again, your help is so appreciated. This has been one of those changes that has you pacing outside wanting to tear your hair out. It's *so* close to completion that it's that much more frustrating. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Calling-Javascript-for-any-event-in-a-parent-tp4676501p4676510.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Calling Javascript for any event in a parent
Hi, Should this action be server side defined and different for every button? If it is the same action for a group of buttons maybe you can use jquery selectors to do some client side logic combined with what Sven suggested. If you could describe better your use case maybe someone can come up with a more precise idea/solution. On Thu, Dec 22, 2016 at 3:46 AM, MissOvenMitts < chantal.lucette.da...@gmail.com> wrote: > I feel like there should be a really easy way to do this, but I just cannot > figure it out. > > I have an AjaxFallbackDefaultDataTable. As normal, this table has links in > it for table paging, a footer with a dropdown allowing the user to change > how many items per page, etc. > > I want to run a piece of extra javascript every time any of these links > run. > > For example, every time the user changes table pages, I want to run: > target.appendJavaScript("alert('You clicked a button!')"); > > I don't have access to each of the links in the table to add this manually > to the onClick events, nor would I want to repeat the code for every one of > those links even if I did have access. > > Is there a sweeping way to do that? I thought I could just add an 'onload' > behavior to the table or something, but that doesn't seem to work. I know > that the parent can see that ajax occurs in it's children since things like > IAjaxIndicatorAware work whenever a child's ajax event gets called. I just > don't know how to use/access these calls. > > Thanks for any help you can offer! > > -- > View this message in context: http://apache-wicket.1842946. > n4.nabble.com/Calling-Javascript-for-any-event-in-a-parent-tp4676501.html > Sent from the Users forum mailing list archive at Nabble.com. > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > -- Regards - Ernesto Reinaldo Barreiro
Re: Calling Javascript for any event in a parent
Hi, have you tried "global listeners"? https://ci.apache.org/projects/wicket/guide/7.x/guide/ajax.html Have fun Sven On 22.12.2016 03:46, MissOvenMitts wrote: I feel like there should be a really easy way to do this, but I just cannot figure it out. I have an AjaxFallbackDefaultDataTable. As normal, this table has links in it for table paging, a footer with a dropdown allowing the user to change how many items per page, etc. I want to run a piece of extra javascript every time any of these links run. For example, every time the user changes table pages, I want to run: target.appendJavaScript("alert('You clicked a button!')"); I don't have access to each of the links in the table to add this manually to the onClick events, nor would I want to repeat the code for every one of those links even if I did have access. Is there a sweeping way to do that? I thought I could just add an 'onload' behavior to the table or something, but that doesn't seem to work. I know that the parent can see that ajax occurs in it's children since things like IAjaxIndicatorAware work whenever a child's ajax event gets called. I just don't know how to use/access these calls. Thanks for any help you can offer! -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Calling-Javascript-for-any-event-in-a-parent-tp4676501.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Calling Javascript for any event in a parent
I feel like there should be a really easy way to do this, but I just cannot figure it out. I have an AjaxFallbackDefaultDataTable. As normal, this table has links in it for table paging, a footer with a dropdown allowing the user to change how many items per page, etc. I want to run a piece of extra javascript every time any of these links run. For example, every time the user changes table pages, I want to run: target.appendJavaScript("alert('You clicked a button!')"); I don't have access to each of the links in the table to add this manually to the onClick events, nor would I want to repeat the code for every one of those links even if I did have access. Is there a sweeping way to do that? I thought I could just add an 'onload' behavior to the table or something, but that doesn't seem to work. I know that the parent can see that ajax occurs in it's children since things like IAjaxIndicatorAware work whenever a child's ajax event gets called. I just don't know how to use/access these calls. Thanks for any help you can offer! -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Calling-Javascript-for-any-event-in-a-parent-tp4676501.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org