Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
620
Resizing grid in Initialize event
posted

I am almost there, but not quite .... I am setting the width and height of my grid server-side, and under certain conditions I want to reduce the height of the grid through the Initialize client-side event.  So I do this by using jQuery to select the grid and then setting it's height (using the jQuery function).  This sets the grid element's clientHeight, but the results are not visible until I sort a column.

Alternatively if I call the _adjustGridLayout method on the grid this works too.  I don't understand why the grid doesn't notice the change in height until it is prodded.  Any ideas?

Parents
No Data
Reply
  • 10240
    posted

    Hi AlistairWood,

    During what event are you setting height and width of the grid server-side? You may be encountering page life cycle event conflicts. If possible I would recommend setting the height and width entirely client-side or entirely server side. Is there a reason to do both?

    For this inquiry, realizing you are looking at doing this with jQuery, what I have for you is a javascript solution. Let me know if this works for you:

     

    function WebHierarchicalDataGrid1_ContainerGrid_Initialize(sender, eventArgs)

    {      

        var width = screen.width;

        var height = screen.height; 

     

        sender.get_element().style.width = "400px";

        sender.get_element().style.height = "400px";

    }

    So for whatever height and width the user sets on the grid, these settings here during initialization will be the size the grid gets.

     

    You can for testing set functions that fire on button click to resize the grid again:

    function

    resizeLarger() {

       

    var grid = $find("<%=webhierarchicaldatagrid1.clientid>");

       

    if (grid != null) {

            grid.get_element().style.width =

    "800px";

    grid.get_element().style.height =

    "600px";

        }

    }

     

    function

    resizeSmaller() {

       

    var grid = $find("<%=webhierarchicaldatagrid1.clientid>");

       

    if (grid != null) {

            grid.get_element().style.width =

    "300px";

            grid.get_element().style.height =

    "300px";

        }

    }

    ..

    <input id="Button1" type="button" value="ReSize Grid (Larger)" onclick="resizeLarger()" />

    <input id="Button2" type="button" value="ReSize Grid (Smaller)" onclick="resizeSmaller()" />

     

    I have attached my sample for your reference. Please note that I omitted the style sheets due to file size constraints. For proper styling of the grid you will need to bring the ig_res folder back into the project. You can do this by opening the project in the designer and select 'OK' when prompted to accept the style sheets.

     

    Please let me know if you need any additional assistance regarding this matter.

     

    WHDG_resize_test.zip
Children