jsgrid.field.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. (function(jsGrid, $, undefined) {
  2. function Field(config) {
  3. $.extend(true, this, config);
  4. this.sortingFunc = this._getSortingFunc();
  5. }
  6. Field.prototype = {
  7. name: "",
  8. title: null,
  9. css: "",
  10. align: "",
  11. width: 100,
  12. visible: true,
  13. filtering: true,
  14. inserting: true,
  15. editing: true,
  16. sorting: true,
  17. sorter: "string", // name of SortStrategy or function to compare elements
  18. headerTemplate: function() {
  19. return (this.title === undefined || this.title === null) ? this.name : this.title;
  20. },
  21. itemTemplate: function(value, item) {
  22. return value;
  23. },
  24. filterTemplate: function() {
  25. return "";
  26. },
  27. insertTemplate: function() {
  28. return "";
  29. },
  30. editTemplate: function(value, item) {
  31. this._value = value;
  32. return this.itemTemplate(value, item);
  33. },
  34. filterValue: function() {
  35. return "";
  36. },
  37. insertValue: function() {
  38. return "";
  39. },
  40. editValue: function() {
  41. return this._value;
  42. },
  43. _getSortingFunc: function() {
  44. var sorter = this.sorter;
  45. if($.isFunction(sorter)) {
  46. return sorter;
  47. }
  48. if(typeof sorter === "string") {
  49. return jsGrid.sortStrategies[sorter];
  50. }
  51. throw Error("wrong sorter for the field \"" + this.name + "\"!");
  52. }
  53. };
  54. jsGrid.Field = Field;
  55. }(jsGrid, jQuery));