jQuery UI Widgets Forums Grid getrowdatabyid returns 'undefined' after refreshing source

This topic contains 5 replies, has 2 voices, and was last updated by  Justintkw 7 years, 10 months ago.

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

  • Justintkw
    Participant

    After refreshing the grid data through the following code:

                var source = $('#jqxgrid_AvalCS').jqxGrid('source');
                source.localdata = AvailCSList;
                var new_dataAdapter = new $.jqx.dataAdapter(source);
                source.dataBind();
                $("#jqxgrid_AvalCS").jqxGrid({ source: new_dataAdapter });
                $('#jqxgrid_AvalCS').jqxGrid('updatebounddata');

    I can no longer get the row data by id.

    var rowdata = $('#jqxgrid_AvalCS').jqxGrid('getrowdatabyid', rowID); returns undefined.

    However, I can still get the row data by the index of the row very same row

    var rowdata = $('#jqxgrid_AvalCS').jqxGrid('getrowdata', rowIndex); returns data without issue.

    Please advise.

    Thank you.


    Justintkw
    Participant

    I found the quick fix: by also re-entery the id of the source (source.id = Whatever).

    This is a bit inconsistent though: that the control assumes that the field definition hasn’t changed, and yet requires the user to re-enter the id upon reload.


    Dimitar
    Participant

    Hello Justintkw,

    The proper way of updating the grid’s source is the following:

    source.localdata = AvailCSList; // this is the original "source" variable
    dataAdapter.dataBind(); // "dataAdapter" is the original jqxDataAdapter instance the grid is bound to
    $('#jqxgrid_AvalCS').jqxGrid('updatebounddata');

    Best Regards,
    Dimitar

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


    Justintkw
    Participant

    Thanks, Dimitar.

    I know that I can reference the grid’s original source from another function (outside the grid’s script block) by doing this:

    var source = $(‘#jqxgrid_AvalCS’).jqxGrid(‘source’);

    But how do I reference the original jqxDataAdapter?


    Dimitar
    Participant

    Hello Justintkw,

    Here is how to get both dynamically:

    var dataAdapter = $('#jqxgrid_AvalCS').jqxGrid('source'); // because you have initially set the grid's "source" property to the data adapter instance
    var source = dataAdapter._source;

    Your code will then become:

    var dataAdapter = $('#jqxgrid_AvalCS').jqxGrid('source');
    var source = dataAdapter._source;
    source.localdata = AvailCSList;
    dataAdapter.dataBind();

    Best Regards,
    Dimitar

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


    Justintkw
    Participant

    Wow. You are so clear with your explanation, Dimitar! I wish all responses to questions were this clear. THANK YOU!

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

You must be logged in to reply to this topic.