jQWidgets Forums

jQuery UI Widgets Forums Grid grid not restoring column sizes on "loadstate" …

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  stephan 12 years ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author

  • stephan
    Participant

    Hi,

    I found that the grid refuses to restore column sizes saved with “savestate” when calling “loadstate”.

    As always a fiddle to reproduce the problem I’m having:
    http://jsfiddle.net/_stephan_/bN6Cq/3/

    * first drag one of the columns really small, e.g column 1
    * now click ‘Save State’
    * now click ‘Render’
    * as you can see ‘render’ will restore all columns to their default size
    * now click ‘Load State’

    You should observe that the column 1 is not restored to its really small size, even though that is the sized that got saved.

    NOTE: I use ‘render’ in my test for simplicity and because it reproduces the issue. In my real application I actually want to load previously saved settings into a table after creating it. The real world use case is that tables store their settings during use, eg. in a cookie, and at a later time restore them when the application is run again.

    Attempting to call “loadstate” on a grid after creating it produces the same problem as documented above for “render” : The grid refuses to restore the column sizes, even though it is EXACTLY the same table as when the settings were saved. Since ‘render’ reproduces the problem I ruled out that I somehow (re)create the grid incorrectly.

    Regards,
    Stephan


    Peter Stoev
    Keymaster

    Hi,

    The initialization of the Grid is not much correct. In the code the “width” property of the columns is not set so the Grid assumes that the Width will be ‘auto’ and should auto-resize such columns.

    Here’s what you need to change in your code:

    $("#jqxgrid").jqxGrid({
    width: 400,
    height: 200,
    source: dataAdapter,
    pageable: true,
    columnsresize : true,
    columns: [{
    text: 'Company Name', width: 100,
    }, {
    text: 'Contact Name', width: 100
    }, {
    text: 'Country', width: 200
    }]
    });

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    stephan
    Participant

    Hi Peter,

    The issue which concerns me is: the user sets a desired size, by dragging the column divider, but the grid implementation rejects this when calling “loadstate”. I actually checked the data that the grid returns when calling “savestate”. It contains the correct clumn size as set by the user. It is the “loadstate” function which refuses to restore this size. Isn’t it a bit strange to have a function “loadstate” that actually does not load the state as it is represented in the “savestate” data ?

    So maybe you can help me with coding this correctly ? Because I do not know how to wrap this concept around the jqxGrid API … The columns should indeed have an initial size of “automatic” (I autogenerate them from database content where I do not have or know a suitable initial width). But whenever the user decides to change a column size manually I want this size to be saved and also restored.

    I mean: the first solution that comes to my mind is to have some sort of “force width” flag for “loadstate”, where I can explicitly request that YES, I want exactly the width as represented in the saved state, without the software deciding to ignore some of the width values. Yet the way I see it this would requrie a grid API change. So I am wondering: is there something I can do with the grid as it is right now ? Some workaround ?

    My second idea is to totally ignore “loadstate” and attempt to code a similar function myself based on the data returned by “savestate”. Barring other API problems this might actually work. Yet it begs the question of why “loadstate” exists in the first place. Ok, it would also mean a lot of extra work for me … thats why I am asking for an alternative 🙂

    Regards,
    Stephan

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.