1 Reply Latest reply on Oct 23, 2019 8:22 AM by Duncan Mills-Oracle

    Setting selection is not working in OjTable from JS


      Hello Team,

      I am using ojTable in one of my assignment and there is a feature to add columns on button click and to make the First newly created column as selected.

      For this I was first fetching the selection as $("#preview").ojTable("option", "selected") and then after some refresh I am again setting it back as $("#preview").ojTable("option", "selected", selection);

      It works well when I set the first column, but it crashes when  I add second column and I get below error


      Uncaught (in promise) TypeError: Cannot read property 'getElementsByClassName' of null
          at oj.TableDomUtils.getTableElementsByClassName (ojtable.js:16004)
          at t.<computed>.<computed>._setHeaderColumnSelection (ojtable.js:10234)
          at t.<computed>.<computed>._setHeaderColumnSelection (widget.js:4)
          at t.<computed>.<computed>.<anonymous> (ojtable.js:10974)
          at Set.forEach (<anonymous>)
          at t.<computed>.<computed>._applySelected (ojtable.js:10971)
          at t.<computed>.<computed>._applySelected (widget.js:4)
          at t.<computed>.<computed>._setSelected (ojtable.js:11022)
          at t.<computed>.<computed>._setSelected (widget.js:4)
          at t.<computed>.<computed>._setOption (ojtable.js:4674)


      It was also working fine before JET version 7.2 .

      Before Jet 7.2  was trying to fetch selection with $("#preview").ojTable("option", "selection")  and setting it back as $("#preview").ojTable("option", "selection", selection);


      I am looking for suggestions as , I am not sure what else I need to correct in terms of JET update.



        • 1. Re: Setting selection is not working in OjTable from JS
          Duncan Mills-Oracle

          You are indeed using old syntax you should be able to set the property directly not via the options


          document.getElementById('preview').selected = selection;


          Or even better, have

          <oj-table selected="{{selection}}" ...>


          and the update to a "selection" observable would cause the change automatically, providing that the timing is right - ie. the table has the column before you change the selection.