Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery dialog height and vertical scrollbar

I am returning data via ajax to populate a jquery dialog. The ajax is basically an html table with a variable amount of rows.

I'd like the dialog to expand to show the rows, up to a certain vertical size (350px), at which point it should show a vertical scrollbar.

So, this seems to work fine - the dialog resizes correctly depending on the number of rows. But, I never get the vertical scrollbar - so if I have 20 rows, then I only get to see the last 9.

How do I force the vertical scrollbar if the height would have been more than 350px?

$.ajax({
    type: 'POST',
    url: 'myurl',
    data: postdata,
    dataType: 'json',
    success: function (result) {
        if (result.success && result.data) {
            var $dialog = $('<div></div>').html(result.data).dialog({
                autoOpen: false,
                title: 'History',
                modal: true,
                height: Math.min((result.rows * 25) + 150, 350),
                width: 800
            });
            $dialog.dialog('open');

        }
        event.preventDefault();
    }
});
like image 591
JonoB Avatar asked May 12 '12 15:05

JonoB


3 Answers

You should add css property overflow:auto for content div.

$("<div></div>").css({height:"350px", overflow:"auto"});

If you need ONLY vertical scroll overflow-y:auto and overflow-x:hidden

like image 129
Eugene Trofimenko Avatar answered Sep 28 '22 00:09

Eugene Trofimenko


use css max-height: 350px; and overflow:auto; .. should be fine

like image 35
yeahman Avatar answered Sep 28 '22 00:09

yeahman


I know this is kind of old but none of these worked for me. Here is what is working as of jQuery UI 1.10.

 $("#helptext").dialog({
        title: 'Blog Help',
        autoOpen: false,
        width: '90%',
        height: ($(window).height() - 200),
        modal: true
  });

Adjust Height and width as you like. I have allot of text in my dialog and didn't want to scroll the whole page.

like image 24
Robert Avatar answered Sep 28 '22 02:09

Robert