David
David

Reputation: 4281

cannot read properties of null (reading 'insertAdjacentHTML') while updating the store

Cannot read properties of null (reading 'insertAdjacentHTML') while updating the store.

I am trying to update my store manually by changing some data.

Here is my code.

updateFieldData: function (selectedDRecord) {
        if (selectedDRecord.id != undefined || selectedDRecord.id != null) {
            let _this = this;
            let groupkey = sessionStorage.getItem('groupKey');
            var rowExapnaderGridData = Ext.ComponentQuery.query('#' + groupkey)[0].getStore();    // this is my gridstore
            var tempStore = [];
            var salesRowData = rowExapnaderGridData.getData().items;
            for (var i = 0; i < salesRowData.length; i++) {
                tempStore.push(salesRowData[i].data);
            }
            for (var i = 0; i < tempStore.length; i++) {
               tempStore[i].value = "somevalue";
            }
            rowExapnaderGridData.loadData(tempStore);
        }

    },

This is working fine while creating but when I am updating I am getting the following error.

Uncaught TypeError: Cannot read properties of null (reading 'insertAdjacentHTML')
    at ctor.insertHtml (ext-all.js?_dc=1654269040829:20:911890)
    at ctor.doInsert (ext-all.js?_dc=1654269040829:20:481469)
    at ctor.append (ext-all.js?_dc=1654269040829:20:481393)
    at ctor.refresh (ext-all.js?_dc=1654269040829:20:1600777)
    at ctor.refresh (ext-all.js?_dc=1654269040829:20:1619324)
    at ctor.refresh (ext-all.js?_dc=1654269040829:20:1862004)
    at ctor.refreshView (ext-all.js?_dc=1654269040829:20:1609433)
    at ctor.onDataRefresh (ext-all.js?_dc=1654269040829:20:1609149)
    at ctor.onDataRefresh (ext-all.js?_dc=1654269040829:20:1870226)
    at ctor.fire (ext-all.js?_dc=1654269040829:20:153709)

I have checked in other places but didn't get much support w.r.t.ExtJS.

Upvotes: 1

Views: 1727

Answers (1)

Arthur
Arthur

Reputation: 413

The code can be simplified like this:

if (!Ext.isEmpty(selectedDRecord.id)) {
   const groupkey = sessionStorage.getItem('groupKey'),
         rowExpanderGridData = Ext.ComponentQuery.query('#' + groupkey)[0].getStore();
   
   Ext.each(rowExpanderGridData, function(record) {
       record.set('fieldname', 'some value'); //'fieldname' is the field that you want to change; 'some value' the new value for it
   });

   rowExpanderGridData.commitChanges();
}
   

Alternatively, you could create a new models array and load them in the store using loadRecords().

Upvotes: 1

Related Questions