none
Add table row to existing table with the Javascript API RRS feed

  • Question

  • This is my first time messing with the Javascript API for Office.

    I want to update a table from a binding, but I'm running into the problem where I'm attempting to update to a row that isn't part of the table, which throws back the invalid startRow or startColumn error. Is there a way to extend the row count of a table in the Javascript API without reloading the whole table?

    Thursday, August 27, 2015 3:12 PM

Answers

  • Hi David,

    >> I'm running into the problem where I'm attempting to update to a row that isn't part of the table, which throws back the invalid startRow or startColumn error. Is there a way to extend the row count of a table in the Javascript API without reloading the whole table?

    I am not sure what you mean with “where I'm attempting to update to a row”? Based on your later description, it seems that you want to add rows to a table. If so, I suggest you select the table, add binding to the current selection in the document with Bindings.addFromSelectionAsync, then add new rows to the table with TableBinding.addRowsAsync method. The code below shows a simple demo:

    //addFromSelectionAsync
    function addFromSelectionAsync() {
        Office.context.document.bindings.addFromSelectionAsync(Office.BindingType.Table, { id: 'addFromSelection' },
           function (asyncResult) {
               app.showNotification('Added new binding with type: ' + asyncResult.value.type + ' and id: ' + asyncResult.value.id);
           });
    }
    //add rows
    function addRows() {
        Office.context.document.bindings.getByIdAsync("addFromSelection",
            function (asyncResult) {
                var binding = asyncResult.value;
                binding.addRowsAsync([["hello", "word"]], function (asyncResult) {
                    app.showNotification( asyncResult.value);
                });
            })
    }

    You could call the functions with click events. For more information about this, you could refer the link below:

    # Bindings.addFromSelectionAsync method (JavaScript API for Office)
    https://msdn.microsoft.com/EN-US/library/office/fp142282.aspx
    # TableBinding.addRowsAsync method (JavaScript API for Office)
    https://msdn.microsoft.com/EN-US/library/office/fp160990.aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, August 28, 2015 7:14 AM