Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Feat/filter complex object #68

Merged
merged 2 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/app/examples/grid-clientside.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,28 @@ export class GridClientSideComponent implements OnInit {
},
{ id: 'utcDate', name: 'UTC Date', field: 'utcDate', formatter: Formatters.dateTimeIsoAmPm, sortable: true, minWidth: 115,
type: FieldType.dateUtc, outputType: FieldType.dateTimeIsoAmPm, filterable: true, filter: { model: Filters.compoundDate } },
{ id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', minWidth: 85, maxWidth: 85, formatter: Formatters.checkmark,
{
id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven.isEffort', minWidth: 85, maxWidth: 85,
type: FieldType.boolean,
sortable: true,

// to pass multiple formatters, use the params property
// also these formatters are executed in sequence, so if you want the checkmark to work correctly, it has to be the last formatter defined
formatter: Formatters.multiple,
params: { formatters: [Formatters.complexObject, Formatters.checkmark] },

// when the "field" string includes the dot "." notation, the library will consider this to be a complex object and Filter accordingly
filterable: true,
filter: {
// We can also add HTML text to be rendered (any bad script will be sanitized) but we have to opt-in, else it will be sanitized
// enableRenderHtml: true,
// collection: [{ value: '', label: '' }, { value: true, label: 'True', labelPrefix: `<i class="fa fa-check"></i> ` }, { value: false, label: 'False' }],

collection: [ { value: '', label: '' }, { value: true, label: 'True' }, { value: false, label: 'False' } ],
collection: [ { isEffort: '', label: '' }, { isEffort: true, label: 'True' }, { isEffort: false, label: 'False' } ],
customStructure: {
value: 'isEffort',
label: 'label'
},
model: Filters.singleSelect,

// we could add certain option(s) to the "multiple-select" plugin
Expand Down Expand Up @@ -162,6 +174,7 @@ export class GridClientSideComponent implements OnInit {
const randomPercent = randomBetween(0, 100);
const randomHour = randomBetween(10, 23);
const randomTime = randomBetween(10, 59);
const randomIsEffort = (i % 3 === 0);

tempDataset.push({
id: i,
Expand All @@ -173,7 +186,10 @@ export class GridClientSideComponent implements OnInit {
start: (i % 4) ? null : new Date(randomYear, randomMonth, randomDay), // provide a Date format
usDateShort: `${randomMonth}/${randomDay}/${randomYearShort}`, // provide a date US Short in the dataset
utcDate: `${randomYear}-${randomMonthStr}-${randomDay}T${randomHour}:${randomTime}:${randomTime}Z`,
effortDriven: (i % 3 === 0)
effortDriven: {
isEffort: randomIsEffort,
label: randomIsEffort ? 'Effort' : 'NoEffort',
}
});
}

Expand Down
10 changes: 8 additions & 2 deletions src/app/modules/angular-slickgrid/services/filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
SlickEvent,
OperatorString
} from './../models/index';
import { castToPromise } from './utilities';
import { castToPromise, getDescendantProperty } from './utilities';
import { FilterFactory } from '../filters/filterFactory';
import { Subject } from 'rxjs/Subject';
import * as isequal_ from 'lodash.isequal';
Expand Down Expand Up @@ -185,10 +185,16 @@ export class FilterService {
if (!columnDef) {
return false;
}

const fieldName = columnDef.queryField || columnDef.queryFieldFilter || columnDef.field;
const fieldType = columnDef.type || FieldType.string;
const filterSearchType = (columnDef.filterSearchType) ? columnDef.filterSearchType : null;
let cellValue = item[fieldName];

let cellValue = item[columnDef.queryField || columnDef.queryFieldFilter || columnDef.field];
// when item is a complex object (dot "." notation), we need to filter the value contained in the object tree
if (fieldName.indexOf('.') >= 0) {
cellValue = getDescendantProperty(item, fieldName);
}

// if we find searchTerms use them but make a deep copy so that we don't affect original array
// we might have to overwrite the value(s) locally that are returned
Expand Down