After that I was thinking of integrating JSLink with some of the very useful jQuery plugins. In this article I am showing how to integrate a jQuery table sorter plugin with SharePoint 2013 JSLink. I have used the tablesorter plugin by Christian Bach for demo purposes.
http://mottie.github.io/tablesorter/docs/index.html
Download the package from the preceding maintained table sorter site and upload the required CSS and JavaScript under the SiteAssets folder on the root site.
I have created a custom list with the following columns. Added these columns in default view. You can create a separate view also.

Then added some test contents to show the functionality working.

Created one JSLink (Student_Filter_Script.js) file that will alter the UI of the view. The JavaScript Link file is as in the following.
- (function () {
- var overrideCtx = {};
- overrideCtx.Templates = {};
- overrideCtx.Templates.Header = "<div class='pager'>Page: <select class='gotoPage'></select><img src='/sites/Demo/SiteAssets/addons/pager/icons/first.png' class='first' alt='First' title='First page' /><img src='/sites/Demo/SiteAssets/addons/pager/icons/prev.png' class='prev' alt='Prev' title='Previous page' /><span class='pagedisplay'></span> <!-- this can be any element, including an input --><img src='/sites/Demo/SiteAssets/addons/pager/icons/next.png' class='next' alt='Next' title='Next page' /><img src='/sites/Demo/SiteAssets/addons/pager/icons/last.png' class='last' alt='Last' title= 'Last page' /><select class='pagesize'><option selected='selected' value='10'>10</option><option value='20'>20</option><option value='30'>30</option><option value='40'>40</option></select></div><table id='myTable' class='tablesorter'><thead><tr><th>Name</th><th>Major</th><th>Sex</th><th>English</th><th>Hindi</th><th>Calculus</th><th>Geometry</th></tr></thead><tfoot><tr><th>Name</th><th>Major</th><th>Sex</th><th>English</th><th>Hindi</th><th>Calculus</th><th>Geometry</th></tr></tfoot><tbody>";
- overrideCtx.Templates.Footer = "</tbody></table><div class='pager'>Page: <select class='gotoPage'></select><img src='/sites/Demo/SiteAssets/addons/pager/icons/first.png' class='first' alt='First' title='First page' /><img src='/sites/Demo/SiteAssets/addons/pager/icons/prev.png' class='prev' alt='Prev' title='Previous page' /><span class='pagedisplay'></span> <!-- this can be any element, including an input --><img src='/sites/Demo/SiteAssets/addons/pager/icons/next.png' class='next' alt='Next' title='Next page' /><img src='/sites/Demo/SiteAssets/addons/pager/icons/last.png' class='last' alt='Last' title= 'Last page' /><select class='pagesize'><option selected='selected' value='10'>10</option><option value='20'>20</option><option value='30'>30</option><option value='40'>40</option></select></div>";
- overrideCtx.Templates.Item = CustomDemoItem;
- overrideCtx.OnPostRender = [];
- overrideCtx.OnPostRender.push(function(){ /* invoke your plugin code here to ensure the plugin has the content to work against */
- $(function()
- {
- // define pager options
- var pagerOptions = {
- // target the pager markup - see the HTML block below
- container: $(".pager"),
- // output string - default is '{page}/{totalPages}'; possible variables: {page}, {totalPages}, {startRow}, {endRow} and {totalRows}
- output: '{startRow} - {endRow} / {filteredRows} ({totalRows})',
- // if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty
- // table row set to a height to compensate; default is false
- fixedHeight: true,
- // remove rows from the table to speed up the sort of large tables.
- // setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled.
- removeRows: false,
- // go to page selector - select dropdown that sets the current page
- cssGoto: '.gotoPage'
- };
- // Initialize tablesorter
- // ***********************
- $("table")
- .tablesorter({
- theme: 'blue',
- headerTemplate : '{content} {icon}', // new in v2.7. Needed to add the bootstrap icon!
- widthFixed: true,
- widgets: ['zebra', 'filter']
- })
- // initialize the pager plugin
- // ****************************
- .tablesorterPager(pagerOptions);
- });
- });
- SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
- })();
- function CustomDemoItem(ctx)
- {
- var html = "";
- html = "<tr>";
- html += "<td>" + ctx.CurrentItem.Title + "</td>";
- html += "<td>" + ctx.CurrentItem.Name + "</td>";
- html += "<td>" + ctx.CurrentItem.Sex + "</td>";
- html += "<td>" + ctx.CurrentItem.English + "</td>";
- html += "<td>" + ctx.CurrentItem.Hindi + "</td>";
- html += "<td>" + ctx.CurrentItem.Calculus + "</td>";
- html += "<td>" + ctx.CurrentItem.Geometry + "</td>";
- html += "</tr>";
- return html;
- }

I added references for the following CSS and JavaScript files in the page layout. I added that in the page layout but you can add it to the master page depending on your requirements.
- <!-- jQuery file -->
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
- <!-- css stylesheet refrences -->
- <link href="/sites/Demo/SiteAssets/css/theme.blue.css" rel="stylesheet" type="text/css" />
- <link href="/sites/Demo/SiteAssets/addons/pager/jquery.tablesorter.pager.css" rel="stylesheet" type="text/css" />
- <!-- Tablesorter js -->
- <script type="text/javascript" src="/sites/Demo/SiteAssets/js/jquery.tablesorter.js"></script>
- <script type="text/javascript" src="/sites/Demo/SiteAssets/addons/pager/jquery.tablesorter.pager.js"></script>
- <script type="text/javascript" src="/sites/Demo/SiteAssets/js/jquery.tablesorter.widgets.js"></script>

Set the value as in the following.
- ~sitecollection/_catalogs/masterpage/JS_Link/Student_Filter_Script.js
The complete contribution, development and license rights remain with the team that have developed the tablesorter plugin. This article is just to show the integration of SharePoint 2013 JSLink with the jQuery plugin.

Karthik Muthu KaruppanPosted Mar 24, 2015, 10:58 AM
useful