Infrequent Error

Posted by: matth on 31 January 2018, 12:17 am EST

    • Post Options:
    • Link

    Posted 31 January 2018, 12:17 am EST

    I am using this snippet to find an item using a key to change one of the fields:

    function searchGridandUpdate(idkey, qty) {
                var fg = document.getElementById('flexGrid');
                var wfg = wijmo.Control.getControl(fg).itemsSource.items;
                var item;
                var pos;
                for (var i = 0; i < wfg.length; i++) {
                    if (wfg[i].OrderItemKey === idkey) {
                        item = wfg[i];
                        pos = i;
                        break;
                    }
                }
                wfg[pos].QtyRemaining = wfg[pos].QtyRemaining - qty;
                wijmo.Control.getControl(fg).collectionView.refresh(wfg[pos]);
                if (wfg[pos].QtyRemaining <= 0) {
                    wijmo.Control.getControl(fg).collectionView.remove(wfg[pos]);
                }
            };
    

    Seldomly I am getting a pos not defined error. I am expecting that it should always find the key that I am looking for. Is there any way to harden this? Is there a better way to look up a value in the data grid? Your thoughts are appreciated.

    Matt

  • Posted 31 January 2018, 12:18 am EST

    I have only seen the error in a production environment and never in debugging.

  • Posted 1 February 2018, 10:07 am EST

    Hi Matthew,

    I would suggest you update your code to this snippet:

    
            function searchGridandUpdate(idkey, qty) {
                var fg = document.getElementById('flexGrid');
                var wfg = wijmo.Control.getControl(fg).itemsSource.items;
                for (var i = 0; i < wfg.length; i++) {
                    if (wfg[i].OrderItemKey === idkey) {
                        wfg[i].QtyRemaining = wfg[i].QtyRemaining - qty;
                        wijmo.Control.getControl(fg).collectionView.refresh(wfg[i]);
                        if (wfg[i].QtyRemaining <= 0) {
                           wijmo.Control.getControl(fg).collectionView.remove(wfg[i]);
                        }
                        break;
                    }
                }
                
            };
    
    

    ~nilay

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels