Skip to content

Commit

Permalink
Merge pull request #1050 from dcleao/7.1.0.0-BACKLOG-16390
Browse files Browse the repository at this point in the history
[BACKLOG-16390] It is not possible to filter a single row in the data table
  • Loading branch information
pamval authored May 15, 2017
2 parents 976b50f + a5484ce commit 653f97f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ define([
* Returns a view for the subset of rows of a data table
* that are selected by this filter.
*
* @param {!pentaho.data.Table} dataTable - The data table to filter.
* @param {!pentaho.type.filter.Abstract} filter - The filter.
*
* @return {!pentaho.data.TableView} A view of the filtered data table.
*
Expand Down Expand Up @@ -275,6 +275,25 @@ define([
return dataView;
},

/**
* Gets a value that indicates if a given filter includes a given row.
*
* @param {!pentaho.type.filter.Abstract} filter - The filter.
* @param {number} rowIndex The row index (zero-based).
*
* @return {boolean} `true` if the filter includes the row; `false`, otherwise.
*
* @throws {pentaho.type.ValidationError} When the filter is not valid,
* the first error returned by the `validate` method.
*/
filterMatchesRow: function(filter, rowIndex) {

filter.assertValid();

var elem = new ElementMock(this, rowIndex);
return filter._contains(elem);
},

/**
* Creates a CDA dataset.
*
Expand Down
56 changes: 56 additions & 0 deletions impl/client/src/test/javascript/pentaho/data/Table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,62 @@ define([
expect(view.getValue(1, 1)).toBe(12000);
});
}); // #filter

describe("#filterMatchesRow(filter, rowIndex)", function() {

var context = new Context();
var AbstractFilter = context.get(abstractFilterFactory);
var CustomFilter = AbstractFilter.extend({_contains: function() { return false; }});

var data = new DataTable({
model: [
{name: "product", type: "string", label: "Product"},
{name: "sales", type: "number", label: "Sales"},
{name: "inStock", type: "boolean", label: "In Stock"}
],
rows: [
{c: [{v: "A"}, {v: 12000}, {v: true }]},
{c: [{v: "B"}, {v: 6000}, {v: true }]},
{c: [{v: "C"}, {v: 12000}, {v: false}]},
{c: [{v: "D"}, {v: 1000}, {v: false}]},
{c: [{v: "E"}, {v: 2000}, {v: false}]},
{c: [{v: "F"}, {v: 3000}, {v: false}]},
{c: [{v: "G"}, {v: 4000}, {v: false}]}
]
});

it("should return `false` when a filter does not selects the row", function() {
var filter = new CustomFilter();

var result = data.filterMatchesRow(filter, 0);

expect(result).toBe(false);
});

it("should return `true` when a filter does select the row", function() {
var filter = new CustomFilter();

spyOn(filter, "_contains").and.callFake(function(elem) {
return elem.getv("product") === "A";
});

var result = data.filterMatchesRow(filter, 0);

expect(result).toBe(true);
});

it("should return `false` when a filter selects another row", function() {
var filter = new CustomFilter();

spyOn(filter, "_contains").and.callFake(function(elem) {
return elem.getv("product") === "A";
});

var result = data.filterMatchesRow(filter, 1);

expect(result).toBe(false);
});
}); // #filterMatchesRow
});

describe("columns -", function() {
Expand Down

0 comments on commit 653f97f

Please sign in to comment.