webismymind / editablegrid

EditableGrid is an open source Javascript library aimed at turning HTML tables into advanced editable components. It focuses on simplicity: only a few lines of code are required to get your first table up and running.
http://www.editablegrid.net
Other
795 stars 272 forks source link

Sorts on Columns with nulls crash #73

Closed Wombatpm closed 7 years ago

Wombatpm commented 9 years ago

I don't know if this is a bug or an initialization error on my part.

I'm creating a grid from this json consisting of

{"metadata":[
    {"name":"origin","label":"Origin zipcode","datatype":"string","editable":true},
    {"name":"dest","label":"Dest zipcode","datatype":"string","editable":true},
    {"name":"pallet","label":"#Pallet","datatype":"integer","editable":true},
    {"name":"weight","label":"Weight","datatype":"double(lb,0,dot,comma,0,-)","editable":true},
    {"name":"value","label":"Value","datatype":"double($,2,dot,comma,1,-)","editable":true},
    {"name":"specialequipment","label":"Request Special Equipment","datatype":"string","editable":true,"values":
        {"Cargo Van":"Cargo Van","Reefer/Heater":"Reefer/Heater","Flat Bed":"Flat Bed","Straight Truck":"Straight Truck",
        "Other Truck":"Other Truck","Hand Cart":"Hand Cart","Lift Gate":"Lift Gate",
        "Pallet Jack":"Pallet Jack","Straps":"Straps","Tarps":"Tarps","Pads":"Pads"},
        },
    {"name":"loading","label":"Can Shipper Load?","datatype":"boolean","editable":true},
    {"name":"unloading","label":"Can Receiver Unload?","datatype":"boolean","editable":true},
    {"name":"facility","label":"Facility Type","datatype":"string","editable":true,"values":{"CGX":"1:CGX","Moore Wallace":"2:Moore Wallace",
    "3:RRD":"RRD","Vendor": "Vendor","Customer Location":"Customer Location","Other":"Other"}},
    {"name":"action","label":"Record Actions","datatype":"html","bar":true,"editable":false,"values":null}
],

"data":[
    {"id":1, "values":{"origin":null,"dest":null,"pallet":null,"weight":null,"value":null,}}
]}

If I inadvertently sort the table before entering data, editablegrid_utils.js throws an exception "null" has no method .toLowerCase(). Stepping through the code, it happens in

EditableGrid.prototype.sort_alpha = function(a,b) 
{
      if (a[0].toLowerCase()==b[0].toLowerCase()) return 0;
      return a[0].toLowerCase().localeCompare(b[0].toLowerCase());
};.  

Now I could change the initialization logic, but i wonder should null be tested for before doing sorts on strings.

timosperisen commented 8 years ago

I think this was fixed in commit 03cb920847ea71ecbb4c27e8e987759f13613b09