Datatable rows containing ui-dialog links
Datatable rows containing ui-dialog links
digitalprecision
Posts: 5Questions: 0Answers: 0
Afternoon. We built an app using Datatables and wanted to add some extra functionality where users could click a 'per row' link which would open a jquery ui-dialog box.
Everything works pretty well except for one issue; when a user uses a form control to increase pagesize or paginate, the links to open up a ui-dialog box no longer work, instead the user is taken to the actual page. This only happens for links that aren't rendered upon initial page load so I think it has something to do with not calling fnDraw() after a user clicks a paginate link.
For example our default page size is 10 rows. A user can click any of the links associated with these first 10 rows and the ui-dialog box renders as expected. When a user increases page size to 50 (from 10) the ui-dialog links beyond the initial 10 do not work.
Thx in advance for any help.
Everything works pretty well except for one issue; when a user uses a form control to increase pagesize or paginate, the links to open up a ui-dialog box no longer work, instead the user is taken to the actual page. This only happens for links that aren't rendered upon initial page load so I think it has something to do with not calling fnDraw() after a user clicks a paginate link.
For example our default page size is 10 rows. A user can click any of the links associated with these first 10 rows and the ui-dialog box renders as expected. When a user increases page size to 50 (from 10) the ui-dialog links beyond the initial 10 do not work.
Thx in advance for any help.
This discussion has been closed.
Replies
How are you adding the link?
[code]
jQuery(document).ready(function() {
jQuery(function() {
jQuery("div#overlay_jquery_get_dialog4cd872f0cc36d").dialog({
autoOpen: false,
zIndex: 6000,
modal: true
});
});
jQuery( "a#jquery_get_dialog4cd872f0cc36d").click(function() {
if (jQuery("div#overlay_jquery_get_dialog4cd872f0cc36d").dialog("isOpen")) {
jQuery("div#overlay_jquery_get_dialog4cd872f0cc36d").html( "" );
jQuery("div#overlay_jquery_get_dialog4cd872f0cc36d").dialog( "close" );
} else {
jQuery.get(jQuery(this).attr("href"), function (data) { jQuery("div#overlay_jquery_get_dialog4cd872f0cc36d").html(data); });
jQuery("div#overlay_jquery_get_dialog4cd872f0cc36d").dialog( "open" );
}
return false;
});
});
[/code]
[code]
jQuery( "a#jquery_get_dialog4cd872f0cc36d").click(function() {
[/code]
to
[code]
jQuery( "a#jquery_get_dialog4cd872f0cc36d").live('click', function() {
[/code]
it should work, but what I am a bit confused about is the selector ("a#jquery_get_dialog4cd872...."), do you have multiple anchor tags with the same id?
-richard
To answer your 2nd question, no, each anchor tag has a different id.
The change you suggested works better, but still not fully. It opens up the html that is supposed to be in the dialog box in the actual table cell.
[code]
jQuery( "a#jquery_get_dialog4cd872f0cc36d").click(function(e) {
e.preventDefault();
if (jQuery("div#overlay_jquery_get_dialog4cd872f0cc36d").dialog("isOpen")) { ...SNIP
} else {
jQuery.get(jQuery(this).attr("href"), function (data) { ...SNIP
});
[/code]
a) don't create the dialog until the link is clicked;
b) destroy the dialog upon close
If you think about it you are 'if'ing a condition that will never be met (a modal dialog will never be open when you are able to click an element NOT in the dialog), I pretty much always initialize my dialogs only when they are needed, and destroy them when they are closed, unless the content for them is totally static or I am using an ajax call to populate the content dynamically.
hth,
-richard