├── LICENSE.txt ├── bower.json ├── package.json ├── CONTRIBUTING.md ├── jquery.dynatable.css ├── README.md ├── PROPRIETARY_LICENSE.html ├── jquery.dynatable.js └── vendor └── jquery-1.7.2.min.js /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Dynatable: A funner, semantic, HTML5+JSON, interactive table plugin. 2 | Copyright (C) 2013 Steve Schwartz 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU Affero General Public License as 6 | published by the Free Software Foundation, either version 3 of the 7 | License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero General Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero General Public License 15 | along with this program. If not, see http://www.gnu.org/licenses/. 16 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dynatable", 3 | "description": "A funner, semantic, HTML5+JSON, interactive table plugin.", 4 | "version": "0.3.1", 5 | "keywords": [ 6 | "table", 7 | "datatables", 8 | "dynamic" 9 | ], 10 | "authors": [ 11 | { 12 | "name": "Steve Schwartz", 13 | "email": "steve@alfajango.com", 14 | "homepage": "http://www.alfajango.com/blog" 15 | } 16 | ], 17 | "dependencies": { 18 | "jquery": ">=1.6" 19 | }, 20 | "main": "jquery.dynatable.js", 21 | "repository" : [ 22 | { 23 | "type": "git", 24 | "url": "https://github.com/alfajango/jquery-dynatable.git" 25 | } 26 | ], 27 | "license": [ 28 | { 29 | "name": "AGPL", 30 | "url": "http://www.dynatable.com/license" 31 | }, 32 | { 33 | "name": "Proprietary License", 34 | "url": "http://www.dynatable.com/license" 35 | } 36 | ], 37 | "homepage": "http://www.dynatable.com", 38 | "ignore": [ 39 | "**/.*", 40 | "CONTRIBUTING.md", 41 | "node_modules", 42 | "vendor", 43 | "test", 44 | "tests" 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Dynatable", 3 | "description": "A funner, semantic, HTML5+JSON, interactive table plugin.", 4 | "version": "0.3.1", 5 | "keywords": [ 6 | "table", 7 | "datatables", 8 | "dynamic table" 9 | ], 10 | "maintainers": [ 11 | { 12 | "name": "Steve Schwartz", 13 | "email": "steve@alfajango.com", 14 | "web": "http://www.alfajango.com/blog" 15 | } 16 | ], 17 | "contributors": [ 18 | { 19 | "name": "Steve Schwartz", 20 | "email": "steve@alfajango.com", 21 | "web": "http://www.alfajango.com/blog" 22 | } 23 | ], 24 | "dependencies": { 25 | "jquery": "1.6" 26 | }, 27 | "bugs": { 28 | "mail": "support@alfajango.com", 29 | "web": "https://github.com/alfajango/jquery-dynatable/issues" 30 | }, 31 | "repositories" : [ 32 | { 33 | "type": "git", 34 | "url": "https://github.com/alfajango/jquery-dynatable.git" 35 | } 36 | ], 37 | "licenses": [ 38 | { 39 | "name": "AGPL", 40 | "url": "http://www.dynatable.com/license" 41 | }, 42 | { 43 | "name": "Proprietary License", 44 | "url": "http://www.dynatable.com/license" 45 | } 46 | ], 47 | "homepage": "http://www.dynatable.com" 48 | } 49 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Dynatable is released under the Free Software Foundation's 4 | GNU Affero General Public License (AGPL). 5 | 6 | Contributors agree that any contributions are owned by the copyright holder 7 | and that contributors have absolutely no rights to their contributions. 8 | 9 | To get started, [sign the Contributor License 10 | Agreement](https://www.clahub.com/agreements/alfajango/jquery-dynatable). 11 | 12 | ## Tests 13 | 14 | Currently the testing process consists of opening [the Dynatable 15 | documentation](http://os.alfajango.com/dynatable) 16 | ([source code 17 | here](https://github.com/alfajango/alfajango.github.com/blob/master/_posts/2012-01-09-dynatable.md)) in 18 | each browser and making sure every example works. This is fine for the 19 | initial release, since it serves the dual purpose of helping us write 20 | the documentation and having a written functional use-case at once. 21 | However, one of the top priorities now is to automate each use-case in 22 | the docs as a test case within an automated test suite. 23 | 24 | If anyone out there thinks this sounds like fun, please contact me or 25 | even go ahead and create an issue/pull request. Otherwise, it will be at 26 | teh top of my priority list until I can get to it. 27 | -------------------------------------------------------------------------------- /jquery.dynatable.css: -------------------------------------------------------------------------------- 1 | /* 2 | * jQuery Dynatable plugin 0.3.1 3 | * 4 | * Copyright (c) 2014 Steve Schwartz (JangoSteve) 5 | * 6 | * Dual licensed under the AGPL and Proprietary licenses: 7 | * http://www.dynatable.com/license/ 8 | * 9 | * Date: Tue Jan 02 2014 10 | */ 11 | th { 12 | background: #006a72; 13 | } 14 | th a { 15 | color: #fff; 16 | } 17 | th a:hover { 18 | color: #fff; 19 | text-decoration: underline; 20 | } 21 | 22 | .dynatable-search { 23 | float: right; 24 | margin-bottom: 10px; 25 | } 26 | 27 | .dynatable-pagination-links { 28 | float: right; 29 | } 30 | 31 | .dynatable-record-count { 32 | display: block; 33 | padding: 5px 0; 34 | } 35 | 36 | .dynatable-pagination-links span, 37 | .dynatable-pagination-links li { 38 | display: inline-block; 39 | } 40 | 41 | .dynatable-page-link, 42 | .dynatable-page-break { 43 | display: block; 44 | padding: 5px 7px; 45 | } 46 | 47 | .dynatable-page-link { 48 | cursor: pointer; 49 | } 50 | 51 | .dynatable-active-page, 52 | .dynatable-disabled-page { 53 | cursor: text; 54 | } 55 | .dynatable-active-page:hover, 56 | .dynatable-disabled-page:hover { 57 | text-decoration: none; 58 | } 59 | 60 | .dynatable-active-page { 61 | background: #006a72; 62 | border-radius: 5px; 63 | color: #fff; 64 | } 65 | .dynatable-active-page:hover { 66 | color: #fff; 67 | } 68 | .dynatable-disabled-page, 69 | .dynatable-disabled-page:hover { 70 | background: none; 71 | color: #999; 72 | } 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jQuery Dynatable 2 | 3 | *A funner, semantic, HTML5+JSON, interactive table plugin.* 4 | 5 | See the [full documentation with demos](http://www.dynatable.com). 6 | 7 | ## Why? 8 | 9 | The purpose of Dynatable is to provide a simple, extensible API, which 10 | makes viewing and interacting with larger datasets easy. Dynatable 11 | provides a framework for implementing the most common elements out of 12 | the box, including sorting, searching and filtering. Above 13 | all, I wanted a clean and elegant API that is fun to use. 14 | 15 | ## Quickstart 16 | 17 | To install Dynatable: 18 | 19 | * [Download the latest release](http://jspkg.com/packages/dynatable) 20 | 21 | ## Support 22 | 23 | IRC: [Join us at #dynatable on freenode IRC](https://webchat.freenode.net/?channels=dynatable) 24 | 25 | Bugs and Feature Requests: [Search and open a Github Issue](https://github.com/alfajango/jquery-dynatable/issues) 26 | 27 | Debugging: [Fork and edit this template on JSFiddle](http://jsfiddle.net/ty3b7/) 28 | 29 | Questions: [Ask a question tagged with dynatable on 30 | StackOverflow](http://stackoverflow.com/questions/tagged/dynatable) 31 | 32 | ## TODO: 33 | 34 | * ~~Change `unfilter`s and `filter`s to `reader`s and `writer`s.~~ 35 | * ~~Clean up defaults that are functions, by abstracting into internal 36 | named functions which can be re-used.~~ 37 | * Change default sort functions to underscore-namespaced functions so as 38 | not to conflict with record attributes called e.g. `search`. 39 | * Update sort function implementation to be analogous to search function 40 | implementation (whereby if a sort function matching attribute name is 41 | present, it will be used for that attribute by default). 42 | * Namespace pushstate query parameters by dynatable instance id to 43 | simplify `refreshQueryString` function and prevent conflicts between 44 | multiple pushState-enabled instances on one page. 45 | * ~~Refactor using prototype to abstract dynatable-global functions to 46 | improve memory efficiency for multiple instances on one page.~~ 47 | * Implement configurable sorting algorithm (see 48 | [JS Merge Sort](http://en.literateprograms.org/Merge_sort_%28JavaScript%29) and [Sorting Table](http://blog.vjeux.com/2010/javascript/javascript-sorting-table.html)). 49 | * ~~Change from Object.create method to constructor pattern to improve 50 | performances (see 51 | [benchmark](http://jsperf.com/object-create-vs-constructor-vs-object-literal/7)).~~ 52 | * ~~Use for loops instead of $.each where possible to improve 53 | performance.~~ 54 | * ~~Use strings and/or document fragments for writing to DOM, instead of 55 | jQuery, by default to improve writing performance.~~ 56 | * Use templated strings to write pagination and other inputs. 57 | * Make class names for input elements configurable. 58 | * Use Chrome profiler to find any performance bottlenecks and fix. 59 | * Simplify API by separating internal-only and accessible model 60 | functions. 61 | * Move sorts and queries functions objects to defaults to make easier to 62 | customize and add to on instantiation (like filters and unfilters) 63 | * Try using CSS-only for ProcessingIndicator.position to avoid querying 64 | rendered DOM styling and speed up all operations that position the 65 | indicator (see [CSS absolute 66 | centering](http://codepen.io/shshaw/full/gEiDt)). 67 | * Add data-dynatable-attr="name" support for reading records from 68 | arbitrary markup (so that you don't need to write a custom rowReader 69 | function when starting with e.g. a stylized list). 70 | * Make sort function first lookup settings.sortTypes[attr], then look 71 | directly for sort sorts.functions[attr], and then finally 72 | sorts.guessType only if neither of the first two exist. 73 | * Add global remove/cleanup function (opposite of init) to allow 74 | removing dynatable via JS. 75 | * Support for Zepto? 76 | 77 | ## Tests 78 | 79 | Currently the testing process consists of opening [the Dynatable 80 | documentation](http://os.alfajango.com/dynatable) 81 | ([source code 82 | here](https://github.com/alfajango/alfajango.github.com/blob/master/_posts/2012-01-09-dynatable.md)) in 83 | each browser and making sure every example works. This is fine for the 84 | initial release, since it serves the dual purpose of helping us write 85 | the documentation and having a written functional use-case at once. 86 | However, one of the top priorities now is to automate each use-case in 87 | the docs as a test case within an automated test suite. 88 | 89 | If anyone out there thinks this sounds like fun, please contact me or 90 | even go ahead and create an issue/pull request. Otherwise, it will be at 91 | the top of my priority list until I can get to it. 92 | 93 | ## Contributing 94 | 95 | Please see the [Contributing Guidelines](https://github.com/JangoSteve/jquery-dynatable/blob/master/CONTRIBUTING.md). 96 | 97 | ## Author 98 | 99 | Steve Schwartz - 100 | [JangoSteve on Github](https://github.com/JangoSteve), 101 | [@jangosteve on Twitter](https://twitter.com/jangosteve) 102 | 103 | ![Alfa Jango logo](https://s3.amazonaws.com/s3.alfajango.com/github-readmes/AlfaJango_Logo_Black_noname-tiny.png) 104 | [Alfa Jango Open Source](http://os.alfajango.com) - 105 | [@alfajango on Twitter](https://twitter.com/alfajango) 106 | 107 | ## Copyright and License 108 | 109 | Copyright 2014 Alfa Jango LLC. 110 | 111 | Dual licensed, released under the Free Software Foundation's 112 | GNU Affero General Public License (AGPL), or see [license 113 | information](http://www.dynatable.com/license) for proprietary or 114 | commercial applications. 115 | 116 | ## Miscellaneous 117 | 118 | ### Refactor performance benchmarks 119 | 120 | For version 0.1.0, Dynatable went through a refactor to use prototypal 121 | inheritence as a more memory-efficient foundation. Here are some 122 | off-the-cuff benchmarks I set up when doing this. 123 | 124 | The performance increase was modest, according to these benchmarks, but 125 | more importantly, the code became a bit cleaner and easier to work with. 126 | 127 | http://jsperf.com/dynatable-prototypal-refactor 128 | 129 | http://jsperf.com/dynatable-refactor/3 130 | 131 | Currently, there's still a bit of performance improvement to be gained 132 | by further grouping DOM reads and writes (though they're already mostly 133 | grouped together), and by using JS string concatenation instead of 134 | jQuery to build the HTML for rendering step. 135 | 136 | The new string concatenation has started to roll out in v0.2. 137 | -------------------------------------------------------------------------------- /PROPRIETARY_LICENSE.html: -------------------------------------------------------------------------------- 1 |
2 |

Terms and conditions

3 |
4 |
    5 |
  1. 6 |

    Preamble: This Agreement, signed on Dec 1, 2013 [hereinafter: Effective Date] governs the relationship between you, a private person or the organization on whose behalf you are undertaking the license described below, (hereinafter: Licensee) and Alfa Jango, LLC, a duly registered company in MI, United States whose principal place of business is 1327 Jones Drive, Suite 109, Ann Arbor, MI 48105, MI, United States (Hereinafter: Licensor). This Agreement sets the terms, rights, restrictions and obligations on using [Dynatable] (hereinafter: The Software) created and owned by Licensor, as detailed herein

    7 |
  2. 8 |
  3. 9 |

    License Grant: Licensor hereby grants Licensee a Sublicensable, Assignable, Commercial, Royalty free, Including the rights to create but not distribute derivative works, Non-exclusive license, all with accordance with the terms set forth and other legal restrictions set forth in 3rd party software used while running Software.

    10 |
      11 |
    1. 12 |

      Limited: Licensee may use Software on a per-web-domain basis for the purpose of:

      13 |
        14 |
      1. Running Software on Licensee's Website[s] and Server[s];
      2. 15 |
      3. Allowing 3rd Parties to run Software on Licensee's Website[s] and Server[s];
      4. 16 |
      5. Publishing Software's output to Licensee and 3rd Parties;
      6. 17 |
      7. Distribute verbatim copies of Software's output (including compiled binaries);
      8. 18 |
      9. Modify Software to suit Licensee's needs and specifications.
      10. 19 |
      20 |

      If Software is to be distributed as part of a downloadable, locally-running software application (herinafter: Distributed Package) which includes a copy of Software, outside of a webserver serving Software directly to the end-user's browser on a live-execution basis, the per-web-domain limitation of the purchased Software license will instead apply to the number of copies of the Distributed Package to be distributed. I.e. A 5-domain license would allow for five (5) copies of the Distributed Package to be distributed; likewise, an Unlimited license would allow for unlimited copies of the Distributed Package to be distributed.

      21 |
    2. 22 |
    3. Binary Restricted: Licensee may sublicense Software as a part of a larger work containing more than Software, distributed solely in Object or Binary form under a personal, non-sublicensable, limited license. Such redistribution shall be limited to unlimited codebases.
    4. 23 |
    5. 24 |

      Assignable: Licensee may assign his rights and duties under this license as long as the party who Licensee assigns the license accepts the license in full, and provides Licensor with a written confirmation of Assignment

      25 |
    6. 26 |
    7. 27 |

      Commercial, Royalty Free: Licensee may use Software for any purpose, including paid-services, without any royalties

      28 |
    8. 29 |
    9. 30 |

      Including the Right to Create Derivative Works: Licensee may create derivative works based on Software, including amending Software's source code, modifying it, integrating it into a larger work or removing portions of Software, as long as no distribution of the derivative works is made

      31 |
    10. 32 |
    11. 33 |

      Licensor shall retain full title in Trademarks, and any trademarks and tradenames contained, including Software's names, logos, and all other intellectual property. Unless specifically stated in this license, no license shall be made to use, associate or affiliate Software with Licensee in any manner. Licensee may not use Software's name, tradename, trademarks or logo when distributing derivative works of software to 3rd parties.

      34 |
    12. 35 |
    36 |
  4. 37 |
  5. 38 | Term & Termination: The Term of this license shall be until terminated. Licensor may terminate this Agreement, including Licensee's license in the case where Licensee : 39 |
      40 |
    1. 41 |

      became insolvent or otherwise entered into any liquidation process; or

      42 |
    2. 43 |
    3. 44 |

      exported The Software to any jurisdiction where licensor may not enforce his rights under this agreements in; or

      45 |
    4. 46 |
    5. 47 |

      Licensee was in breach of any of this license's terms and conditions and such breach was not cured, immediately upon notification; or

      48 |
    6. 49 |
    7. 50 |

      Licensee in breach of any of the terms of clause 2 to this license; or

      51 |
    8. 52 |
    9. 53 |

      Licensee otherwise entered into any arrangement which caused Licensor to be unable to enforce his rights under this License.

      54 |
    10. 55 |
    56 |
  6. 57 |
  7. Payment: In consideration of the License granted under clause 2, Licensee shall pay Licensor a fee, via Credit-Card, PayPal or any other mean which Licensor may deem adequate. Failure to perform payment shall construe as material breach of this Agreement.
  8. 58 |
  9. 59 |

    Upgrades, Updates and Fixes: Licensor may provide Licensee, from time to time, with Upgrades, Updates or Fixes, as detailed herein and according to his sole discretion. Licensee hereby warrants to keep The Software up-to-date and install all relevant updates and fixes, and may, at his sole discretion, purchase upgrades, according to the rates set by Licensor. Licensor shall provide any update or Fix free of charge; however, nothing in this Agreement shall require Licensor to provide Updates or Fixes.

    60 |
      61 |
    1. 62 |

      Upgrades: for the purpose of this license, an Upgrade shall be a material amendment in The Software, which contains new features and or major performance improvements and shall be marked as a new version number. For example, should Licensee purchase The Software under version 1.X.X, an upgrade shall commence under number 2.0.0.

      63 |
    2. 64 |
    3. 65 |

      Updates: for the purpose of this license, an update shall be a minor amendment in The Software, which may contain new features or minor improvements and shall be marked as a new sub-version number. For example, should Licensee purchase The Software under version 1.1.X, an upgrade shall commence under number 1.2.0.

      66 |
    4. 67 |
    5. 68 |

      Fix: for the purpose of this license, a fix shall be a minor amendment in The Software, intended to remove bugs or alter minor features which impair the The Software's functionality. A fix shall be marked as a new sub-sub-version number. For example, should Licensee purchase Software under version 1.1.1, an upgrade shall commence under number 1.1.2.

      69 |
    6. 70 |
    71 |
  10. 72 |
  11. 73 |

    Support: Software is provided under an AS-IS basis and without any support, updates or maintenance. Nothing in this Agreement shall require Licensor to provide Licensee with support or fixes to any bug, failure, mis-performance or other defect in The Software.

    74 |
      75 |
    1. 76 |

      Bug Notification: Licensee may provide Licensor of details regarding any bug, defect or failure in The Software promptly and with no delay from such event; Licensee shall comply with Licensor's request for information regarding bugs, defects or failures and furnish him with information, screenshots and try to reproduce such bugs, defects or failures.

      77 |
    2. 78 |
    3. 79 |

      Feature Request: Licensee may request additional features in Software, provided, however, that (i) Licensee shall waive any claim or right in such feature should feature be developed by Licensor; (ii) Licensee shall be prohibited from developing the feature, or disclose such feature request, or feature, to any 3rd party directly competing with Licensor or any 3rd party which may be, following the development of such feature, in direct competition with Licensor; (iii) Licensee warrants that feature does not infringe any 3rd party patent, trademark, trade-secret or any other intellectual property right; and (iv) Licensee developed, envisioned or created the feature solely by himself.

      80 |
    4. 81 |
    82 |
  12. 83 |
  13. 84 |

    Liability: To the extent permitted under Law, The Software is provided under an AS-IS basis. Licensor shall never, and without any limit, be liable for any damage, cost, expense or any other payment incurred by Licensee as a result of Software's actions, failure, bugs and/or any other interaction between The Software and Licensee's end-equipment, computers, other software or any 3rd party, end-equipment, computer or services. Moreover, Licensor shall never be liable for any defect in source code written by Licensee when relying on The Software or using The Software's source code.

    85 |
  14. 86 |
  15. 87 |

    Warranty:

    88 |
      89 |
    1. 90 |

      Intellectual Property: Licensor hereby warrants that The Software does not violate or infringe any 3rd party claims in regards to intellectual property, patents and/or trademarks and that to the best of its knowledge no legal action has been taken against it for any infringement or violation of any 3rd party intellectual property rights.

      91 |
    2. 92 |
    3. 93 |

      No-Warranty: The Software is provided without any warranty; Licensor hereby disclaims any warranty that The Software shall be error free, without defects or code which may cause damage to Licensee's computers or to Licensee, and that Software shall be functional. Licensee shall be solely liable to any damage, defect or loss incurred as a result of operating software and undertake the risks contained in running The Software on License's Server[s] and Website[s].

      94 |
    4. 95 |
    5. 96 |

      Prior Inspection: Licensee hereby states that he inspected The Software thoroughly and found it satisfactory and adequate to his needs, that it does not interfere with his regular operation and that it does meet the standards and scope of his computer systems and architecture. Licensee found that The Software interacts with his development, website and server environment and that it does not infringe any of End User License Agreement of any software Licensee may use in performing his services. Licensee hereby waives any claims regarding The Software's incompatibility, performance, results and features, and warrants that he inspected the The Software.

      97 |
    6. 98 |
    99 |
  16. 100 |
  17. 101 |

    No Refunds: Licensee warrants that he inspected The Software according to clause 7(c) and that it is adequate to his needs. Accordingly, as The Software is intangible goods, Licensee shall not be, ever, entitled to any refund, rebate, compensation or restitution for any reason whatsoever, even if The Software contains material flaws.

    102 |
  18. 103 |
  19. 104 |

    Indemnification: Licensee hereby warrants to hold Licensor harmless and indemnify Licensor for any lawsuit brought against it in regards to Licensee's use of The Software in means that violate, breach or otherwise circumvent this license, Licensor's intellectual property rights or Licensor's title in The Software. Licensor shall promptly notify Licensee in case of such legal action and request Licensee's consent prior to any settlement in relation to such lawsuit or claim.

    105 |
  20. 106 |
  21. 107 |

    Governing Law, Jurisdiction: Licensee hereby agrees not to initiate class-action lawsuits against Licensor in relation to this license and to compensate Licensor for any legal fees, cost or attorney fees should any claim brought by Licensee against Licensor be denied, in part or in full.

    108 |
  22. 109 |
110 |
111 |
112 | -------------------------------------------------------------------------------- /jquery.dynatable.js: -------------------------------------------------------------------------------- 1 | /* 2 | * jQuery Dynatable plugin 0.3.1 3 | * 4 | * Copyright (c) 2014 Steve Schwartz (JangoSteve) 5 | * 6 | * Dual licensed under the AGPL and Proprietary licenses: 7 | * http://www.dynatable.com/license/ 8 | * 9 | * Date: Tue Jan 02 2014 10 | */ 11 | // 12 | 13 | (function($) { 14 | var defaults, 15 | mergeSettings, 16 | dt, 17 | Model, 18 | modelPrototypes = { 19 | dom: Dom, 20 | domColumns: DomColumns, 21 | records: Records, 22 | recordsCount: RecordsCount, 23 | processingIndicator: ProcessingIndicator, 24 | state: State, 25 | sorts: Sorts, 26 | sortsHeaders: SortsHeaders, 27 | queries: Queries, 28 | inputsSearch: InputsSearch, 29 | paginationPage: PaginationPage, 30 | paginationPerPage: PaginationPerPage, 31 | paginationLinks: PaginationLinks 32 | }, 33 | utility, 34 | build, 35 | processAll, 36 | initModel, 37 | defaultRowWriter, 38 | defaultCellWriter, 39 | defaultAttributeWriter, 40 | defaultAttributeReader; 41 | 42 | //----------------------------------------------------------------- 43 | // Cached plugin global defaults 44 | //----------------------------------------------------------------- 45 | 46 | defaults = { 47 | features: { 48 | paginate: true, 49 | sort: true, 50 | pushState: true, 51 | search: true, 52 | recordCount: true, 53 | perPageSelect: true 54 | }, 55 | table: { 56 | defaultColumnIdStyle: 'camelCase', 57 | columns: null, 58 | headRowSelector: 'thead tr', // or e.g. tr:first-child 59 | bodyRowSelector: 'tbody tr', 60 | headRowClass: null, 61 | copyHeaderAlignment: true, 62 | copyHeaderClass: false 63 | }, 64 | inputs: { 65 | queries: null, 66 | sorts: null, 67 | multisort: ['ctrlKey', 'shiftKey', 'metaKey'], 68 | page: null, 69 | queryEvent: 'blur change', 70 | recordCountTarget: null, 71 | recordCountPlacement: 'after', 72 | paginationLinkTarget: null, 73 | paginationLinkPlacement: 'after', 74 | paginationClass: 'dynatable-pagination-links', 75 | paginationLinkClass: 'dynatable-page-link', 76 | paginationPrevClass: 'dynatable-page-prev', 77 | paginationNextClass: 'dynatable-page-next', 78 | paginationActiveClass: 'dynatable-active-page', 79 | paginationDisabledClass: 'dynatable-disabled-page', 80 | paginationPrev: 'Previous', 81 | paginationNext: 'Next', 82 | paginationGap: [1,2,2,1], 83 | searchTarget: null, 84 | searchPlacement: 'before', 85 | searchText: 'Search: ', 86 | perPageTarget: null, 87 | perPagePlacement: 'before', 88 | perPageText: 'Show: ', 89 | pageText: 'Pages: ', 90 | recordCountPageBoundTemplate: '{pageLowerBound} to {pageUpperBound} of', 91 | recordCountPageUnboundedTemplate: '{recordsShown} of', 92 | recordCountTotalTemplate: '{recordsQueryCount} {collectionName}', 93 | recordCountFilteredTemplate: ' (filtered from {recordsTotal} total records)', 94 | recordCountText: 'Showing', 95 | recordCountTextTemplate: '{text} {pageTemplate} {totalTemplate} {filteredTemplate}', 96 | recordCountTemplate: '{textTemplate}', 97 | processingText: 'Processing...' 98 | }, 99 | dataset: { 100 | ajax: false, 101 | ajaxUrl: null, 102 | ajaxCache: null, 103 | ajaxOnLoad: false, 104 | ajaxMethod: 'GET', 105 | ajaxDataType: 'json', 106 | totalRecordCount: null, 107 | queries: {}, 108 | queryRecordCount: null, 109 | page: null, 110 | perPageDefault: 10, 111 | perPageOptions: [10,20,50,100], 112 | sorts: {}, 113 | sortsKeys: [], 114 | sortTypes: {}, 115 | records: null 116 | }, 117 | writers: { 118 | _rowWriter: defaultRowWriter, 119 | _cellWriter: defaultCellWriter, 120 | _attributeWriter: defaultAttributeWriter 121 | }, 122 | readers: { 123 | _rowReader: null, 124 | _attributeReader: defaultAttributeReader 125 | }, 126 | params: { 127 | dynatable: 'dynatable', 128 | queries: 'queries', 129 | sorts: 'sorts', 130 | page: 'page', 131 | perPage: 'perPage', 132 | offset: 'offset', 133 | records: 'records', 134 | record: null, 135 | queryRecordCount: 'queryRecordCount', 136 | totalRecordCount: 'totalRecordCount' 137 | } 138 | }; 139 | 140 | //----------------------------------------------------------------- 141 | // Each dynatable instance inherits from this, 142 | // set properties specific to instance 143 | //----------------------------------------------------------------- 144 | 145 | dt = { 146 | init: function(element, options) { 147 | this.settings = mergeSettings(options); 148 | this.element = element; 149 | this.$element = $(element); 150 | 151 | // All the setup that doesn't require element or options 152 | build.call(this); 153 | 154 | return this; 155 | }, 156 | 157 | process: function(skipPushState) { 158 | processAll.call(this, skipPushState); 159 | } 160 | }; 161 | 162 | //----------------------------------------------------------------- 163 | // Cached plugin global functions 164 | //----------------------------------------------------------------- 165 | 166 | mergeSettings = function(options) { 167 | var newOptions = $.extend(true, {}, defaults, options); 168 | 169 | // TODO: figure out a better way to do this. 170 | // Doing `extend(true)` causes any elements that are arrays 171 | // to merge the default and options arrays instead of overriding the defaults. 172 | if (options) { 173 | if (options.inputs) { 174 | if (options.inputs.multisort) { 175 | newOptions.inputs.multisort = options.inputs.multisort; 176 | } 177 | if (options.inputs.paginationGap) { 178 | newOptions.inputs.paginationGap = options.inputs.paginationGap; 179 | } 180 | } 181 | if (options.dataset && options.dataset.perPageOptions) { 182 | newOptions.dataset.perPageOptions = options.dataset.perPageOptions; 183 | } 184 | } 185 | 186 | return newOptions; 187 | }; 188 | 189 | build = function() { 190 | this.$element.trigger('dynatable:preinit', this); 191 | 192 | for (model in modelPrototypes) { 193 | if (modelPrototypes.hasOwnProperty(model)) { 194 | var modelInstance = this[model] = new modelPrototypes[model](this, this.settings); 195 | if (modelInstance.initOnLoad()) { 196 | modelInstance.init(); 197 | } 198 | } 199 | } 200 | 201 | this.$element.trigger('dynatable:init', this); 202 | 203 | if (!this.settings.dataset.ajax || (this.settings.dataset.ajax && this.settings.dataset.ajaxOnLoad) || this.settings.features.paginate || (this.settings.features.sort && !$.isEmptyObject(this.settings.dataset.sorts))) { 204 | this.process(); 205 | } 206 | }; 207 | 208 | processAll = function(skipPushState) { 209 | var data = {}; 210 | 211 | this.$element.trigger('dynatable:beforeProcess', data); 212 | 213 | if (!$.isEmptyObject(this.settings.dataset.queries)) { data[this.settings.params.queries] = this.settings.dataset.queries; } 214 | // TODO: Wrap this in a try/rescue block to hide the processing indicator and indicate something went wrong if error 215 | this.processingIndicator.show(); 216 | 217 | if (this.settings.features.sort && !$.isEmptyObject(this.settings.dataset.sorts)) { data[this.settings.params.sorts] = this.settings.dataset.sorts; } 218 | if (this.settings.features.paginate && this.settings.dataset.page) { 219 | var page = this.settings.dataset.page, 220 | perPage = this.settings.dataset.perPage; 221 | data[this.settings.params.page] = page; 222 | data[this.settings.params.perPage] = perPage; 223 | data[this.settings.params.offset] = (page - 1) * perPage; 224 | } 225 | if (this.settings.dataset.ajaxData) { $.extend(data, this.settings.dataset.ajaxData); } 226 | 227 | // If ajax, sends query to ajaxUrl with queries and sorts serialized and appended in ajax data 228 | // otherwise, executes queries and sorts on in-page data 229 | if (this.settings.dataset.ajax) { 230 | var _this = this; 231 | var options = { 232 | type: _this.settings.dataset.ajaxMethod, 233 | dataType: _this.settings.dataset.ajaxDataType, 234 | data: data, 235 | error: function(xhr, error) { 236 | _this.$element.trigger('dynatable:ajax:error', {xhr: xhr, error : error}); 237 | }, 238 | success: function(response) { 239 | _this.$element.trigger('dynatable:ajax:success', response); 240 | // Merge ajax results and meta-data into dynatables cached data 241 | _this.records.updateFromJson(response); 242 | // update table with new records 243 | _this.dom.update(); 244 | 245 | if (!skipPushState && _this.state.initOnLoad()) { 246 | _this.state.push(data); 247 | } 248 | }, 249 | complete: function() { 250 | _this.processingIndicator.hide(); 251 | } 252 | }; 253 | // Do not pass url to `ajax` options if blank 254 | if (this.settings.dataset.ajaxUrl) { 255 | options.url = this.settings.dataset.ajaxUrl; 256 | 257 | // If ajaxUrl is blank, then we're using the current page URL, 258 | // we need to strip out any query, sort, or page data controlled by dynatable 259 | // that may have been in URL when page loaded, so that it doesn't conflict with 260 | // what's passed in with the data ajax parameter 261 | } else { 262 | options.url = utility.refreshQueryString(window.location.href, {}, this.settings); 263 | } 264 | if (this.settings.dataset.ajaxCache !== null) { options.cache = this.settings.dataset.ajaxCache; } 265 | 266 | $.ajax(options); 267 | } else { 268 | this.records.resetOriginal(); 269 | this.queries.run(); 270 | if (this.settings.features.sort) { 271 | this.records.sort(); 272 | } 273 | if (this.settings.features.paginate) { 274 | this.records.paginate(); 275 | } 276 | this.dom.update(); 277 | this.processingIndicator.hide(); 278 | 279 | if (!skipPushState && this.state.initOnLoad()) { 280 | this.state.push(data); 281 | } 282 | } 283 | 284 | this.$element.addClass('dynatable-loaded'); 285 | this.$element.trigger('dynatable:afterProcess', data); 286 | }; 287 | 288 | function defaultRowWriter(rowIndex, record, columns, cellWriter) { 289 | var tr = ''; 290 | 291 | // grab the record's attribute for each column 292 | for (var i = 0, len = columns.length; i < len; i++) { 293 | tr += cellWriter(columns[i], record); 294 | } 295 | 296 | return '' + tr + ''; 297 | }; 298 | 299 | function defaultCellWriter(column, record) { 300 | var html = column.attributeWriter(record), 301 | td = '