jQWidgets Forums

jQuery UI Widgets Forums Grid grid event sequence

This topic contains 7 replies, has 2 voices, and was last updated by  Peter Stoev 10 years ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • grid event sequence #68648

    jonno
    Participant

    Hi Folks,

    I need some help with required events or processing sequence is needed to achieve the following:-
    1. Refresh the grid every arbitrary 10 seconds from the jsonp dataAdapter.
    2. If there is a new data row then make a sound.
    3. Highlight the new row

    Thanks

    J

    grid event sequence #68651

    Peter Stoev
    Keymaster

    Hi jonno,

    To highlight a row, use selectrow method. There’s no built in API for checking whether your old data is different from the new data after re-binding the Grid. May be you can store your dataAdapter’s results within the dataAdapter’s callback functions. If I were you, I would write one adapter which makes the Ajax calls, will then check within the adapter’s beforeLoadComplete function whether the new data is different from the old and then will bind the Grid to a new local data adapter.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    grid event sequence #68775

    jonno
    Participant

    Hello Peter,

    Thank you for your response.

    I’ve attempted to use the beforeLoadComplete function.
    From what i understand this function takes two parameters being the new records and old records arrays.
    What i observe is that new and old record arrays are the same, i.e. no difference.
    Am i using this function correctly?

    I first use $(‘#jqxgrid’).jqxGrid(‘updatebounddata’); to get data.
    Then wait in beforeLoadComplete function to determine differences in the data.
    I compare the new and old arrays for any difference but the arrays are the same.

    Here is my code

    refresh_data = function () {
    $(‘#jqxgrid’).jqxGrid(‘updatebounddata’);
    }

    var dataAdapter = new $.jqx.dataAdapter(source,
    {
    formatData: function (data) {
    return “{}”;
    },
    beforeLoadComplete: function (newrecords,oldrecords) {
    if (newrecords.length > oldrecords.length) { // code break here shows both arrays are the same.
    $.playSound(‘sounds/alarm.mp3’);
    }
    return newrecords;
    }

    });

    grid event sequence #68781

    Peter Stoev
    Keymaster

    Hi jonno,

    The only correct is that the function has 2 parameters, but the second parameter is not the old records, it’s the data loaded through jqxDataAdapter, before processing the data. The first parameter is an Array which is the data loaded through jqxDataAdapter after processing the data.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    grid event sequence #68791

    jonno
    Participant

    Peter,

    Thanks for your help.

    For those interested:-

    I used a $(“#jqxgrid”).jqxGrid(“getdatainformation”).rowscount to obtain the current count of rows.
    Then compared to the array passed in from beforeLoadComplete(records) function

    records.length > $(“#jqxgrid”).jqxGrid(“getdatainformation”).rowscount // Check if new records?

    grid event sequence #68792

    Peter Stoev
    Keymaster

    Hi jonno,

    I don’t think that checking the rows count is enough for checking whether you have or do not have new records. For example you may have data with equal records count, but with different data values.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    grid event sequence #68800

    jonno
    Participant

    Peter

    You’re absolutely right there, I’m lucky to have a very simple requirement at this stage.

    In a future version i would like to know which data cells to colourise to signify change.

    I’m guessing comparing the records array from beforeLoadComplete(records) function with another records array of the existing grid recordset?

    Is there an internal array for existing records? or it is accessed via getrowdata?
    var data = $(‘#jqxGrid’).jqxGrid(‘getrowdata’, 0);

    grid event sequence #68803

    Peter Stoev
    Keymaster

    Hi jonno,

    “getrows” method returns the Array of rows displayed in jqxGrid. However, the result depends on whether fitlering or sorting is applied, too. I guess that for your scenario it would be best to have a new variable which stores the dataAdapter.records set and compare the old with new records.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

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

You must be logged in to reply to this topic.