jQWidgets Forums

jQuery UI Widgets Forums Plugins Data Adapter Updating a datasource for dataadapter

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  Gianni 11 years, 9 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Updating a datasource for dataadapter #27570

    Gianni
    Member

    Hello All,

    I have quite a complicated interface, which i have simplified, and some of my widgets are interlinked.

    what i want to know is…what is the best way to update the localarray source of data if it needs to be changed?

    Is there a wrapper function to access the source data in a dataAdapter?

    colourTable = [
    {\'colourcode\' : 1, \'colourlabel\' : \'white\'},
    {\'colourcode\' : 2, \'colourlabel\' : 'green'},
    {\'colourcode\' : 3, \'colourlabel\' : \'red\'},
    {\'colourcode\' : 4, \'colourlabel\' : \'salmon\'},
    {\'colourcode\' : 5, \'colourlabel\' : \'orange\'}
    ];
    colourssource =
    {
    datatype: \"array\",
    datafields: [
    { name: colourcode\', type: \'number\' },
    { name: \'colourlabel\', type: \'string\' },
    ],
    localdata: colourTable,
    updaterow: function (rowid, rowdata, commit) {
    commit(true);
    },
    };
    // adapter for coulours data
    coloursadapter = new $.jqx.dataAdapter(colourssource, {
    autoBind: true
    });
    coloursadapter.dataBind();
    // dropdownlist bound to a grid and a column has (simplified)
    $(\"#dataflow\").jqxGrid(
    {
    width: 500,
    source: dataflowadapter,
    theme: \'office\',
    selectionmode: \'singlerow\',
    autoheight: true,
    editable: true,
    columns: [
    {
    // other datafields here
    text: \'Colour\', datafield: \'colour\', displayfield: \'colourlabel\', columntype: \'dropdownlist\',
    createeditor: function (row, value, editor) {
    editor.jqxDropDownList({ source: coloursadapter, displayMember: \'colourlabel\', valueMember: \'colourcode\' });
    }
    }
    ]
    });

    somewhere in the code i want to make a change to the colour palette based on some user feedback. So for example i might want to change ‘green’ to ‘brown’

    how do i invoke a function to make this change?

    ie i want to change the 2nd item from green to brown and have this shown when i call the dropdown editor in my grid. It seems i want to call the updaterow method but i dont know the syntax.

    Thank you for your time.

    Gianni.

    Updating a datasource for dataadapter #27573

    Peter Stoev
    Keymaster

    Hi Gianni,

    Your “colourTable” is an Array, so you can update it like that:

    colourTable[0][‘colourlabel’] = “Blue”;

    Then you can update the colorsource

    colourssource.localdata = colourTable;

    Btw, the following is wrong and should be removed:

    coloursadapter = new $.jqx.dataAdapter(colourssource, {
    autoBind: true
    });
    coloursadapter.dataBind();

    Binding the Grid does not require calling the dataAdapter’s dataBind or setting autoBind.

    That’s how you should create a dataAdapter:

    var coloursadapter = new $.jqx.dataAdapter(colourssource);

    And that’s how you should refresh the Grid’s source:

    $(\”#dataflow\”).jqxGrid({source: coloursadapter });

    Best Regards,
    Peter Stoev

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

    Updating a datasource for dataadapter #27594

    Gianni
    Member

    Dear Peter,

    I have about 9 fields in the grid….i removed them to make it easier to understand….

    as you can see it has another adapter dataflowadapter which contaions the data for the grid as a whole

    having said that, i wouldnt call $(”#dataflow”).jqxGrid({source: coloursadapter }) would i?

    i was only concerned about the values in the dropdownlist….the coloursadapter was only the source for the dropdown for colour field not for the grid…

    and was a simple dynamic array of values. IT is used in 2 or even 3 grids on the page so i wanted to have it as a little widget…

    Does that make sense?

    Regards Gianni

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

You must be logged in to reply to this topic.