Skip to content

Commit

Permalink
Add value parsers to dist assets.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauris committed Sep 9, 2014
1 parent dcf7e91 commit 3c2d1c4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
32 changes: 28 additions & 4 deletions dist/sensei-grid.js
Expand Up @@ -142,14 +142,38 @@
}
};

// core parsers for cell values
plugin.parsers = {};
plugin.parsers["string"] = function (val) {
return val.toString();
};
plugin.parsers["int"] = function (val) {
return parseInt(val);
};
plugin.parsers["float"] = function (val) {
return parseFloat(val);
};

plugin.getCellData = function ($cell) {
return $cell.text();
var value = $cell.text();
var type = plugin.getCellType($cell);

// parse value according to defined cell type
if (_.has(plugin.parsers, type)) {
value = plugin.parsers[type](value);
}

return value;
};

plugin.getCellColumn = function ($cell) {
return $cell.data("column");
};

plugin.getCellType = function ($cell) {
return $cell.data("type");
};

plugin.getCellDataByIndex = function (row, cell) {
var $row = plugin.getRowByIndex(row);
var $cell = plugin.getCellFromRowByIndex($row, cell);
Expand All @@ -165,7 +189,7 @@
plugin.getCellFromRowByIndex = function ($row, index) {
var $cell = $row.find("td").eq(index);
if ($cell.length === 0) {
throw new Error("Cell does not exist: ", $cell);
throw new Error("Cell does not exist");
}

return $cell;
Expand All @@ -177,7 +201,7 @@
return $(this).data("column") === key;
});
if ($cell.length === 0) {
throw new Error("Cell does not exist: ", $cell);
throw new Error("Cell does not exist");
}

return $cell;
Expand All @@ -194,7 +218,7 @@
plugin.getRowByIndex = function (index) {
var $row = plugin.$el.find("tbody>tr").eq(index);
if ($row.length === 0) {
throw new Error("Row does not exist: ", $row);
throw new Error("Row does not exist");
}

return $row;
Expand Down

0 comments on commit 3c2d1c4

Please sign in to comment.