-
-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
257 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
aldeed:tabular@1.0.3 | ||
aldeed:tabular@1.0.4 | ||
application-configuration@1.0.4 | ||
base64@1.0.2 | ||
binary-heap@1.0.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* global getPubSelector:true, _ */ | ||
|
||
getPubSelector = function getPubSelector(selector, searchString, searchFields, searchCaseInsensitive) { | ||
if (!searchString || !searchFields || searchFields.length === 0) { | ||
return selector; | ||
} | ||
|
||
// See if we can resolve the search string to a number, | ||
// in which case we use an extra query because $regex | ||
// matches string fields only. | ||
var numSearchString = Number(searchString), searches = []; | ||
|
||
_.each(searchFields, function(field) { | ||
var m1 = {}, m2 = {}; | ||
|
||
// String search | ||
m1[field] = {$regex: searchString}; | ||
// DataTables searches are case insensitive by default | ||
if (searchCaseInsensitive !== false) { | ||
m1[field].$options = "i"; | ||
} | ||
searches.push(m1); | ||
|
||
// Number search | ||
if (!isNaN(numSearchString)) { | ||
m2[field] = numSearchString;//{$where: '/' + numSearchString + '/.test(this.' + field + ')'}; | ||
searches.push(m2); | ||
} | ||
}); | ||
|
||
return _.extend({}, selector, {$or: searches}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* global tableInit:true, _, Blaze, Util */ | ||
|
||
/** | ||
* Uses the Tabular.Table instance to get the columns, fields, and searchFields | ||
* @param {Tabular.Table} tabularTable The Tabular.Table instance | ||
* @param {Template} template The Template instance | ||
*/ | ||
tableInit = function tableInit(tabularTable, template) { | ||
var columns = _.clone(tabularTable.options.columns); | ||
var fields = {}, searchFields = []; | ||
|
||
// Loop through the provided columns object | ||
_.each(columns, function (col) { | ||
// The `tmpl` column option is special for this | ||
// package. We parse it into other column options | ||
// and then remove it. | ||
var tmpl = col.tmpl; | ||
if (tmpl) { | ||
col.defaultContent = ""; | ||
col.orderable = false; | ||
col.createdCell = function (cell, cellData, rowData) { | ||
Blaze.renderWithData(tmpl, rowData, cell); | ||
}; | ||
delete col.tmpl; | ||
} | ||
|
||
// Automatically protect against errors from null and undefined | ||
// values | ||
if (!("defaultContent" in col)) { | ||
col.defaultContent = ""; | ||
} | ||
|
||
// Build the list of field names we want included | ||
var dataProp = col.data; | ||
if (typeof dataProp === "string") { | ||
// If it's referencing an instance function, don't | ||
// include it. Prevent sorting and searching because | ||
// our pub function won't be able to do it. | ||
if (dataProp.indexOf("()") !== -1) { | ||
col.sortable = false; | ||
col.searchable = false; | ||
return; | ||
} | ||
|
||
fields[Util.cleanFieldName(dataProp)] = 1; | ||
|
||
// DataTables says default value for col.searchable is `true`, | ||
// so we will search on all columns that haven't been set to | ||
// `false`. | ||
if (col.searchable !== false) { | ||
searchFields.push(Util.cleanFieldNameForSearch(dataProp)); | ||
} | ||
} | ||
|
||
// If we're displaying a template for this field, | ||
// don't pass the data prop along to DataTables. | ||
// This prevents both the data and the template | ||
// from displaying in the same cell. We wait until | ||
// now to do this to be sure that we still include | ||
// the data prop in the list of fields. | ||
if (tmpl) { | ||
col.data = null; | ||
} | ||
}); | ||
|
||
template.tabular.columns = columns; | ||
template.tabular.fields.set(fields); | ||
template.tabular.searchFields = searchFields; | ||
}; |
Oops, something went wrong.