0

My User defined sort function does not work in IE 8.

Object doesn't support property or method 'indexOf'

roles_store.sort([{
    sorterFn: function(v1, v2) {
    var order = ['read-only', 'user', 'admin', 'super'],
        v1o   = order.indexOf(v1.get('role_name')),
        v2o   = order.indexOf(v2.get('role_name'));           

        return v1o < v2o ? -1 : 1;; 
    }
}]);

The following link shows a workaround: How to fix Array indexOf() in JavaScript for Internet Explorer browsers

I tried replacing indexof with Array.prototype.indexOf

v2o = order.Array.prototype.indexOf (v2.get('role_name'));

I apologize if I missed something here

Community
  • 1
  • 1
Micheal
  • 2,272
  • 10
  • 49
  • 93

2 Answers2

1

Use Ext.Array.indexOf, it defers to the native indexOf where possible.

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Array-method-indexOf

Evan Trimboli
  • 29,900
  • 6
  • 45
  • 66
1

IE 8 is a little old and it includes an old javascript version. It doesn´t have a lot of very useful methods that we use everyday. I recommend to include the tiny Array prototype extensions library (link). That library allows you to use all the methods (for arrays) that all new browsers (with newer javascript version) include.

You also can use the Extjs methods as Evan suggests (they work well) but you have to have that in mind all the time and most of the snippets and code samples that you find in internet or this site won´t run (you will have to translate them to use extjs methods). Another problem is that your code will works ok in Chrome and FF but not in IE if you not take care.

It is much more easy and safe to include the extensions that I recommend you, that´s what we did in our own project and it was a great solution.

lontivero
  • 5,235
  • 5
  • 25
  • 42