I was searching today for a few hours for an easy solutions, but i did not find it.
I have a table(#example) with data in it and with a link to a page(allinfo.php) where all the data of particular row is shown(they are not all shown in table). Therefore i would like to make this easier for user. I would like that they can click on the link and the dialog window with content from allinfo.php is shown.
my script in :
$(document).ready(function() {
$('#example a').each(function() {
var $dialog = $('<div></div>')
.append($loading.clon开发者_JAVA技巧e());
var $link = $(this).one('click', function() {
$dialog
.load($link.attr('href') + ' #content')
.dialog({
title: $link.attr('title'),
width: 500,
height: 300
});
$link.click(function() {
$dialog.dialog('open');
return false;
});
return false;
});
});
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"sAjaxSource": "url.php",
"fnServerData": fnDataTablesPipeline,
"sPaginationType": "full_numbers",
} );
} );
So, problem is that table is generated in javascript and i cannot add option of dialog window in there. If i write somewhere else on site: all info and click, everything will work.
Only solution that i can see is, with using "onclick" command, but i do not know how to use it?
so in table should be all info
Thank you for your help!
I would use a combination of .live and $(this).attr('href') and $.ajax you can also use the event object function(event)
Something like this should work, but its a little difficult as I am unable to test against anything:
$(document).ready(function() {
// As soon as the page loads, attach a div for showing content:
$('body').append('<div id="dialogPopup"></div>');
// Setup the dialog:
$('#dialogPopup').dialog({
width: 500,
height: 300,
autoOpen: false});
// Listen to ALL anchors in #example:
$('#example a').live('click', function(e) {
// Don't let the browser follow the link:
e.preventDefault();
// Store a link to the link clicked:
var obj = $(this);
// Store a link to the dialog:
var dia = $('#dialogPopup');
// Empty the content of the popup:
dia.html('');
// Load the contents into the dialog:
dia.load(obj.attr('href') + ' #content')
// Set the title:
.dialog({title: obj.attr('title')})
// Open the dialog:
.dialog('open');
});
$('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
"sAjaxSource": "url.php",
"fnServerData": fnDataTablesPipeline,
"sPaginationType": "full_numbers",
});
});
精彩评论