Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 7th, 2018 57 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. YUI().use('dataschema-xml', 'datatable-sort', function(Y) {
  2.     // This function generates a schema based on contents of a TABLE element
  3.     var getSchemaFromTableNode = function(tableNode) {
  4.         var fields = [],
  5.         // Each record is held in a TR
  6.         schema = {resultListLocator:"tr"},
  7.         // Each field name is held in a TH
  8.         thList = tableNode.all("th");
  9.  
  10.         // Generate field definitions based on TH
  11.         thList.each(function(thNode, i){
  12.             // Note that the XPath indexes are 1-based!
  13.             // String().test();
  14.            
  15.  
  16.             fields.push(
  17.                 {
  18.                     key:thNode.get("text"),
  19.                     sortable: (/^true$/i).test(thNode.getAttribute("data-sortable")),
  20.                     locator:"td["+(i+1)+"]"
  21.                 }
  22.            
  23.             );
  24.  
  25.         }),
  26.        
  27.        
  28.         schema.resultFields = fields;
  29.         return schema;
  30.     };
  31.  
  32.     var tableNode = Y.one("#accounts"),
  33.         // Generate schema dynamically
  34.         schema = getSchemaFromTableNode(tableNode),
  35.         // Create a temporary TBODY container to hold all data TRs
  36.         tbody = document.createElement("tbody"),
  37.         tbodyContainer = document.createDocumentFragment().appendChild(tbody);
  38.  
  39.     // Grab each TR in a TBODY but don't include TRs from the THEAD
  40.     Y.all("#accounts tbody tr").each(function(trNode, i){
  41.         // Cloning the TR keeps it in the document (optional)
  42.         // Append each TR to the container
  43.         tbodyContainer.appendChild(Y.Node.getDOMNode(trNode).cloneNode(true));
  44.     });
  45.  
  46.    
  47.  
  48.    
  49.    
  50.    
  51.     Y.one("#accounts table").hide();
  52.    
  53.  
  54.     table = new Y.DataTable.Base({
  55.         columnset: getSchemaFromTableNode(tableNode).resultFields,
  56.         recordset: Y.DataSchema.XML.apply(schema, tbodyContainer).results
  57.     }).plug(Y.Plugin.DataTableSort,
  58.         lastSortedBy = {
  59.             field: Y.one('#accounts th[data-initial-order]').get("text") ,
  60.             dir: Y.one('#accounts th[data-initial-order]').getAttribute('data-initial-order')
  61.         }
  62.         ).render("#accounts");
  63.  
  64.  
  65.    
  66. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top