zeitlin / jquery-datatables-row-grouping

Automatically exported from code.google.com/p/jquery-datatables-row-grouping
0 stars 0 forks source link

Check that data typeof string before invoking toLowerCase() etc... #34

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. put object as cell data into grid
2. group by column with object in cells

in             
{{{
function _fnGetCleanedGroup(sGroup) {
}}}

add type checking:
{{{
if (sGroup === "" || typeof(sGroup)!='string' ) return "-";
}}}

instead of `typeof(sGroup)!='string'` you can use some serialization in case of 
object

Original issue reported on code.google.com by Penkov.V...@gmail.com on 30 Jul 2012 at 9:12

GoogleCodeExporter commented 9 years ago

Original comment by joc...@gmail.com on 29 May 2013 at 8:22

GoogleCodeExporter commented 9 years ago
This issue crops up for me if the column I attempt to group on contains a bare 
number. The following data will trigger the error.

{
  "data": [
    [
      1,
      "George Washington",
      "US President",
      "New York City",
    ],
    [
      1,
      "Abraham Lincoln",
      "US President",
      "Washington DC",
    ]
  ]
}

The exception occurs in the function _fnGetCleanedGroup which assumes its 
argument will always be a string. Since column data in DataTables is not always 
a string, this is a problemattic. I propose that the body of _fnGetCleanedGroup 
should be changed to something similar to the following:

function _fnGetCleanedGroup(sGroup) {
  var rval = sGroup;
  if (typeof sGroup != 'string') {
    rval = JSON.stringify(sGroup);
  }

  if (rval === "")
    return "-";
  return rval.toLowerCase().replace(
      /[^a-zA-Z0-9\u0080-\uFFFF]+/g, "-"); //fix for unicode characters (Issue 23)
  //return sGroup.toLowerCase().replace(/\W+/g, "-"); //Fix provided by bmathews (Issue 7)
}

Original comment by tim.v...@gmail.com on 13 Mar 2015 at 10:17