jQuery UI Widgets Forums Grid session storage of column structure

This topic contains 3 replies, has 2 voices, and was last updated by  Dimitar 10 years, 9 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • session storage of column structure #27619

    morgenweck
    Participant

    This maybe a 100% stupid question but here goes.

    I want to save the columns property in a session storage. Such as

    var d = [
    { text: ‘Name’, datafield: ‘name’, width: 250 },
    { text: ‘Beverage Type’, datafield: ‘type’, width: 250 },
    { text: ‘Calories’, datafield: ‘calories’, width: 180 },
    { text: ‘Total Fat’, datafield: ‘totalfat’, width: 120 },
    { text: ‘Protein’, datafield: ‘protein’, minwidth: 120 }
    ]

    So then
    sessionStorage.setItem(“SubGrid1_d”, d)

    I want to store a couple of different versions of the column structures so I could have

    var i = [
    { text: ‘Name’, datafield: ‘name’, width: 250 },
    { text: ‘Beverage Type’, datafield: ‘type’, width: 250 }

    ]

    sessionStorage.setItem(“SubGrid1_i”, i)

    then when I set up the grid I could use

    columns: sessionStorage.getItem(“SubGrid1_i”)

    or

    columns: sessionStorage.getItem(“SubGrid1_d”)

    based upon some other condition such as privileges or permissions. Is this possible? Do you happen to know what the syntax would be for the storage?

    Thanks for the help

    session storage of column structure #27653

    Dimitar
    Participant

    Hello morgenweck,

    You can save and load different grid states by using the methods savestate, loadstate and getstate. You can learn more about them in the API Documentation. Please also check out the demo Save/Load Grid State.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    session storage of column structure #27691

    morgenweck
    Participant

    I appreciate the answer but that is not the question. I’m not looking to save the state or load a state, I’m looking to create the grid with different options of the column layout based upon an external condition without have to recreate the data source and all of the other code. In most of the demo examples the url is created by using

    var url = “../sampledata/products.xml”;

    and then using url as a

    root: “Products”,
    record: “Product”,
    id: ‘ProductID’,
    url: url
    };

    I want to expand that to the columns

    so instead of having

    columns: [
    { text: ‘Name’, datafield: ‘name’, hidden: true, width: 250 },
    { text: ‘Beverage Type’, datafield: ‘type’, width: 250 },
    { text: ‘Calories’, datafield: ‘calories’, width: 180 },
    { text: ‘Total Fat’, datafield: ‘totalfat’, width: 120 },
    { text: ‘Protein’, datafield: ‘protein’, minwidth: 120 }
    ]

    I have
    var columns = ‘”[
    { text: ‘Name’, datafield: ‘name’, hidden: true, width: 250 },
    { text: ‘Beverage Type’, datafield: ‘type’, width: 250 },
    { text: ‘Calories’, datafield: ‘calories’, width: 180 },
    { text: ‘Total Fat’, datafield: ‘totalfat’, width: 120 },
    { text: ‘Protein’, datafield: ‘protein’, minwidth: 120 }
    ]”

    and then I use

    columns: columns

    But that code does not work because of all of the single quotes and double quotes and I have tried many different combinations and I was hoping that you might know the right combination.

    Thanks

    session storage of column structure #27751

    Dimitar
    Participant

    Hi morgenweck,

    You can do this but you do not need to quote the value of the columns variable. It should be an array of objects:

    columns: [
    { text: 'Name', datafield: 'name', hidden: true, width: 250 },
    { text: 'Beverage Type', datafield: 'type', width: 250 },
    { text: 'Calories', datafield: 'calories', width: 180 },
    { text: 'Total Fat', datafield: 'totalfat', width: 120 },
    { text: 'Protein', datafield: 'protein', minwidth: 120 }
    ]

    Besides, if you want to quote, everything should be in one line.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

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

You must be logged in to reply to this topic.