none
Problem with TableBinding RRS feed

  • Question

  • Hi,

    I have a situation where I need to remove all rows (except header) from table, using deleteAllDataValuesAsync function, and then I need to create new rows using addRowsAsync function. In Excel everything works perfectly fine. But when it comes to Word, in case where table has only one column, only header remains bound, where rest of the rows doesn't. In case where table has multiple columns again everything works perfectly fine.

    Initially I thought that there is a bug in my code, so I tested this on brand new project and still got same result.

    I hope that you will check this, if you need any additional informations, I'll provide it.

    Best Regards,

    Milos

    Friday, April 22, 2016 2:48 PM

All replies

  • >>>But when it comes to Word, in case where table has only one column, only header remains bound, where rest of the rows doesn't. In case where table has multiple columns again everything works perfectly fine.

    According to your description, I have made a sample to try to reproduce this issue, unfortunately, I can't. So I suggest that you could provide sample code and screenshot to help us reproduce and resolve your issue.

    Thanks for your understanding.
    Monday, April 25, 2016 7:08 AM
  • Hi David,

    Thank you for reply. First of all I forgot to mention that I'm using Word 2016 (not online), on Windows 7, guess this information is also relevant.

    Here is my code: 

                var binding;
    
                $('#addBindingButton').click(function () {
                    Office.context.document.bindings.addFromSelectionAsync(Office.BindingType.Table, function (result) {
                        binding = result.value;
                        binding.addHandlerAsync(Office.EventType.BindingSelectionChanged, function (result) {
                            app.showNotification('binding selection changed ' + result.binding.id);
                        });
                    });
                });
    
                $("#updateButton").click(function () {
                    binding.deleteAllDataValuesAsync(function (result) {
                        var rows = [];
                        if (binding.columnCount === 1) {
                            rows = [["1"], ["2"]];
                        } else if (binding.columnCount === 2) {
                            rows = [["1", "2"], ["3", "4"]];
                        }
    
                        binding.addRowsAsync(rows, function (result) {
                            binding.addHandlerAsync(Office.EventType.BindingSelectionChanged, function (result) {
                                app.showNotification('binding selection changed ' + result.binding.id);
                            });
                        });
                    });
                });

    I also uploaded video with all the steps which cause the problem: 

    https://www.youtube.com/watch?v=IutD23MTI9o


    Best Regards,

    Milos






    • Edited by m41in4 Wednesday, April 27, 2016 1:45 PM
    Monday, April 25, 2016 12:41 PM
  • Hi, m41in4

    Thanks very much for your detail steps to help us reproduce this issue. I’m able to reproduce this issue now. This workaround is you could rebind to a region of a document that contains a table with headers.

    In addition if you have any feedback for Office Dev, please feel free to submit them to User Voice:

    https://officespdev.uservoice.com/

    Thanks for your understanding.
    • Proposed as answer by David_JunFeng Monday, May 2, 2016 2:08 PM
    Tuesday, April 26, 2016 7:01 AM
  • This workaround is you could rebind to a region of a document that contains a table with headers.
    But if I do that, and let's say move the table to different page, and write some text at the place where table was before, then if I select that text, it will be recognized as a table if I'm not mistaken. So that could be a problem.

    Anyway, I've posted the problem at  https://officespdev.uservoice.com/
    Thank you for your help, and quick responses, and have a nice day.
    Tuesday, April 26, 2016 10:31 AM