Skip to content

Commit

Permalink
Improved column type detection
Browse files Browse the repository at this point in the history
  • Loading branch information
McFizh committed Mar 8, 2016
1 parent 354b468 commit 0bcbcfa
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 180 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### Changelog

+ **v1.2.7** - 8.3.2016
- Column type detection ignores empty elements, this makes results more accurate
- Unit testing added for sorting text & numbers

+ **v1.2.6** - 7.3.2016
- Now rows (tr in tbody) can also preserve attributes

Expand Down
5 changes: 3 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slimtable",
"version": "1.2.6",
"version": "1.2.7",
"description": "jQuery plugin to create sortable and pageable table.",
"homepage": "http://slimtable.mcfish.org/",
"license": "MIT",
Expand All @@ -14,7 +14,8 @@
"table",
"ajax",
"paging",
"jquery"
"jquery",
"jquery-plugin"
],

"main": [
Expand Down
4 changes: 2 additions & 2 deletions dist/js/slimtable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(grunt){
" *\n" +
" * Licensed under MIT license.\n" +
" *\n" +
" * @version 1.2.6\n" +
" * @version 1.2.7\n" +
" * @author Pekka Harjamäki\n" +
" */"
},
Expand Down
22 changes: 15 additions & 7 deletions js/slimtable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Licensed under MIT license.
*
* @version 1.2.6
* @version 1.2.7
* @author Pekka Harjamäki
*/

Expand Down Expand Up @@ -175,6 +175,8 @@
* ******************************************************************* */
function processData(data)
{
var l1, l2, t_row;

tbl_data = [];

for(l1=0; l1<data.length; l1++)
Expand Down Expand Up @@ -304,6 +306,7 @@
{
// Remove HTML, TRIM data and create array with cleaned & original data
t_obj = tbl_data[l2].data[l1];

if ( t_obj.clean === null )
{
t_obj = col_settings[l1].stripHtml ? $(html_cleaner_div).html(t_obj.orig).text() : t_obj.orig;
Expand All @@ -313,7 +316,9 @@
t_obj = t_obj.clean;
}

match_arr[ return_row_type( t_obj ) ]++;
t_attr = returnRowType( t_obj );
if(t_attr > 0)
match_arr[ t_attr ]++;
}

col_settings[l1].rowType = $.inArray( Math.max.apply(this, match_arr) , match_arr );
Expand All @@ -339,8 +344,8 @@
// Convert values to dates
if ( t_attr == 4 )
{
t1 = t_obj.split(/[.\/-]/);
tbl_data[l2].data[l1].clean = new Date ( t1[2], t1[1], t1[0] );
t_obj = t_obj.split(/[.\/-]/);
tbl_data[l2].data[l1].clean = new Date ( t_obj[2], t_obj[1], t_obj[0] );
}
}
}
Expand Down Expand Up @@ -436,13 +441,17 @@
/* ******************************************************************* *
*
* ******************************************************************* */
function return_row_type(data)
function returnRowType(data)
{
var patt_01 = /[^0-9]/g,
patt_02 = /^[0-9]+([\.,][0-9]+)?$/,
patt_03 = /^([0-9]+([\.,][0-9]+)?)\s*[%$£e]?$/,
patt_04 = /^[0-9]{1,2}[.-\/][0-9]{1,2}[.-\/][0-9]{4}$/;

// Given element is empy
if( data.length === 0 )
return(-1);

// Given element doesn't containt any other characters than numbers
if( !patt_01.test(data) )
return(1);
Expand Down Expand Up @@ -533,7 +542,7 @@
if(num<0 || num>=pages)
return;

paging_start = parseInt(num*items_per_page);
paging_start = num * parseInt(items_per_page);
createTableBody();
}

Expand All @@ -545,7 +554,6 @@

function handleHeaderClick(e) {
var idx = $(this).index(),
l1,
pos = $.inArray(idx,sort_list);

//
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "slimtable",
"description": "jQuery plugin to create sortable and pageable table.",
"version": "1.2.6",
"version": "1.2.7",
"author": "Pekka Harjamäki <[email protected]>",
"homepage": "http://slimtable.mcfish.org",
"license": "MIT",
Expand Down
32 changes: 0 additions & 32 deletions slimtable.jquery.json

This file was deleted.

Loading

0 comments on commit 0bcbcfa

Please sign in to comment.