tabalinas / jsgrid

Lightweight Grid jQuery Plugin
http://js-grid.com
MIT License
1.52k stars 352 forks source link

nested property name in sorter #1397

Open standik opened 3 years ago

standik commented 3 years ago

Hello, first of all thanks for the great job! Your grid is wonderful :-)

I have found a little issue when sorting on select field and couldn't work out other solution than amend your code. Basically, in jsgrid.min.js there is a code: "a b.sortingFunc(c[b.name], d[b.name])". But that does not work on nested properties. If b.name is eg. "resource.id", then c[b.name] returns undefined. In fact, in this case it should be c["resource"]["id"], but that is not universal enough. Eventually, I rewrote the formula to "ab.sortingFunc(eval("c."+b.name),eval("d."+b.name))". That works, but using eval is not particulary good practice.

my definition of field: { name: "resource.id", title: "Resource", type: "select", items: loadResources(), valueField: "id", textField: "name", filtering: true, width: 50 }

For completeness, the object representing the row (note the nested resource which has id and makes the sorting formula not work):

{resource: {id: 1}, ratio: 1, dateFrom: "2021-06-01T00:00:00.000Z", dateTo: "2021-06-08T00:00:00.000Z"}