Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1233
updating datasource with rowtemplate
posted

i have a grid using a row template to show images.  i want to update the data source and have the row template update the row based on the new data.  What is the best way to do this?

Parents Reply
  • 6279
    Suggested Answer
    posted in reply to Ian Fletcher

    Hi Ian,

    Here is the approach I can recommend:

    1. Capture the vertical scrollbar's top position during the dataBinding event (it won't be set at all when the grid is databound for the 1st time)
    2. Set a handler function for the dataRendered event and call scrollTop() in it based on the captured position

    I'm pasting the suggested script below - you can see a demo of it in the HTML sample I'm attaching to this reply.

    var verticalScrollPos;
    
    $(function () {
        $('#grid1').igGrid({
            virtualization: false,
            autoGenerateColumns: false,
            width: '500px',
            height: '500px',
            columns: [
                { headerText: "Product ID", key: "ProductID", width: "100px", dataType: "number" },
                { headerText: "Units in Stock", key: "UnitsInStock", width: "150px", dataType: "number" },
                { headerText: "Product Description", key: "ProductDescription", width: "150px", dataType: "string" },
                { headerText: "Unit Price", key: "UnitPrice", width: "100px", dataType: "string" }
            ],
            dataSource: namedData,
            primaryKey: "ProductID",
            features: [
                {
                    name: "Selection",
                    mode: "row"
                }
            ],
            dataBinding: function(evt, ui) {
                if(ui.owner.scrollContainer()[0]){
                    verticalScrollPos = ui.owner.scrollContainer().scrollTop();
                }
            },
            dataRendered: function(evt, ui) {
                if(verticalScrollPos)
                {
                    $(ui.owner.scrollContainer()).scrollTop(verticalScrollPos);
                    
                }
            }
        });
    });
    

    Let us know if you need more details.

    Beast Regards,
    Borislav 

    t69132-Ian.zip
Children