jQWidgets Forums

jQuery UI Widgets Forums Grid SCROLL BAR PROBLEM WITH JSON DATA SOURCE

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

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

  • mc
    Member

    My grid takes data from a mysql db by json .
    And it updates whole grid data by this function every 10 secs.

    RefreshNodeStatusID = setInterval(RefreshNodeStatus, 10000); //

    function RefreshNodeStatus()
    {

    $("#jqxgrid").jqxGrid('updatebounddata');

    }

    My problem is, scroll bar goes to the top position at every refresh cycle.
    i tried to set scroll position in this refresh function but it didnot help because it is flashing and going to top place again.

    How can i catch end of grid refresh event?
    Or is there any way to save scroll bar position when we work with mysql data sources?


    Peter Stoev
    Keymaster

    Hi mc,

    – The ‘bindingcomplete’ event is raised when a binding operation is completed.
    – The ‘scrolloffset’ method can be used for setting scroll’s position. It accepts 2 params – left and top position. The method should be called when the Grid is loaded and binding is completed.
    – The following code example demonstrates how to keep the scroll position when the data is updated.

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="../../scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxexpander.js"></script>
    <script type="text/javascript" src="../../jqwidgets/jqxdragdrop.js"></script>
    <script type="text/javascript" src="../../scripts/gettheme.js"></script>
    <script type="text/javascript" src="generatedata.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    var theme = getTheme();
    var source =
    {
    localdata: generatedata(20),
    datatype: "array"
    };
    var dataAdapter = new $.jqx.dataAdapter(source);
    var columns = [
    { text: 'First Name', dataField: 'firstname', width: 100 },
    { text: 'Last Name', dataField: 'lastname', width: 100 },
    { text: 'Product', dataField: 'productname', width: 180 },
    { text: 'Quantity', dataField: 'quantity', width: 80, cellsalign: 'right' },
    { text: 'Unit Price', dataField: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2' },
    { text: 'Total', dataField: 'total', cellsalign: 'right', minwidth: 100, cellsformat: 'c2' }
    ];
    // create data grid.
    $("#grid").jqxGrid(
    {
    width: 670,
    height: 300,
    source: dataAdapter,
    theme: theme,
    columns: columns
    });
    // init buttons.
    $("#refresh").jqxButton({ theme: theme });
    $("#clear").jqxButton({ theme: theme });
    $("#refresh").click(function () {
    var value = $("#grid").jqxGrid('vScrollBar').jqxScrollBar('value');
    source.localdata = generatedata(20);
    $("#grid").jqxGrid('updatebounddata');
    $("#grid").jqxGrid('scrollTo', 0, value);
    });
    $("#clear").click(function () {
    $("#grid").jqxGrid('clear');
    });
    });
    </script>
    </head>
    <body class='default'>
    <div id='jqxWidget'>
    <div id="grid">
    </div>
    <div style="margin-top: 10px;">
    <input id="refresh" type="button" value="Refresh Data" />
    <input id="clear" type="button" value="Clear" />
    </div>
    </div>
    </body>
    </html>

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    mc
    Member

    I found my mistake thank you very much.

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

You must be logged in to reply to this topic.