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
585
Problems with add/insert/delete row and autoCommit
posted

I need to initialize the igGrid with autoCommit set to False in order to make deleteRow() cancellable from the UI perspective, as I want to have the deleted row shows italic and cross-out prior to committing.

For addRow(), using $(#grid).igGridUpdating("addRow", values); works fine regardless autoCommit value. Since I need to provide a primary key for other feature on a row, I use this instead:

$(#grid).data("igGrid").dataSource.addRow("MyPrimaryKey", values, true);

$(#grid).igGrid("dataBind");

However, adding row to the dataSource directly will lose the transaction that causing the new row cannot be saved. Any suggestion?

For insertRow(), I was told and able to use the following code to insert a row at a desired location:

$(#grid).data("igGrid").dataSource.insertRow("MyPrimaryKey", values, rowIndex, true);

$(#grid).igGrid("dataBind");

However, same reason as addRow(), newly inserted row cannot be saved due to the losing transaction. While primary key is needed for other feature on the row, any suggestion?

Just to re-state my requirements:

- primary key is needed

- autoCommit needs to be FALSE

Thanks!

  • 23953
    Verified Answer
    Offline posted

    Hi Erica,

    Calling igGrid.dataBind is rebinding the data source which clears the accumulated transactions.

    You have two options to resolve your issue.

    1.For addRow method don't call igGrid.dataBind but use igGrid.renderNewRow method in order to make the grid aware of the row. Note that this method will render the row at the end of the grid.

    2.For the insertRow you should call the igGrid.dataBind, so you have to persist the transactions on calling igGrid.dataBind.
    Note that this requires using a private variables, so this solution may not work between Ignite UI releases.
    Here is an example code:

    function rebind() {

        var pendingTransactions = $("#grid1").data("igGrid").dataSource.pendingTransactions();

        var allTransactions = $("#grid1").data("igGrid").dataSource.allTransactions();

        $("#grid1").igGrid("dataBind");

        $("#grid1").data("igGrid").dataSource._transactionLog = pendingTransactions;

        $("#grid1").data("igGrid").dataSource._accumulatedTransactionLog = allTransactions;

    }

    Hope this helps,

    Martin Pavlov

    Infragistics, Inc.