# HG changeset patch # User Thierry Florac # Date 1444233843 -7200 # Node ID 8337e31c9edbb7a47b7032fccecc82bd608bce51 # Parent 7b6902a80d290d31d14747b9cf7b8092218480bb Added custom columns types detectors and sorters diff -r 7b6902a80d29 -r 8337e31c9edb src/pyams_skin/resources/js/myams-dataTables.js --- a/src/pyams_skin/resources/js/myams-dataTables.js Wed Oct 07 18:03:25 2015 +0200 +++ b/src/pyams_skin/resources/js/myams-dataTables.js Wed Oct 07 18:04:03 2015 +0200 @@ -45,6 +45,89 @@ /** + * Custom sorting plug-in + */ + $.fn.dataTableExt.aTypes.unshift( + function(sData) { + if (sData !== null && sData.match(/^(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/[0-3][0-9]{3}$/)) { + return 'date-euro'; + } + return null; + } + ); + + $.fn.dataTableExt.aTypes.unshift( + function(sData) { + if (sData !== null && sData.match(/^(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/[0-3][0-9]{3} - ([0-1][0-9]|2[0-3]):[0-5][0-9]$/)) { + return 'datetime-euro'; + } + return null; + } + ); + + $.extend($.fn.dataTableExt.oSort, { + + // numeric-comma column sorter + "numeric-comma-asc": function(a, b) { + var x = a.replace(/,/, ".").replace(/ /g, ''); + var y = b.replace(/,/, ".").replace(/ /g, ''); + x = parseFloat(x); + y = parseFloat(y); + return ((x < y) ? -1 : ((x > y) ? 1 : 0)); + }, + "numeric-comma-desc": function(a, b) { + var x = a.replace(/,/, ".").replace(/ /g, ''); + var y = b.replace(/,/, ".").replace(/ /g, ''); + x = parseFloat(x); + y = parseFloat(y); + return ((x < y) ? 1 : ((x > y) ? -1 : 0)); + }, + + // date-euro column sorter + "date-euro-pre": function(a) { + var trimmed = $.trim(a); + if (trimmed != '') { + var frDate= trimmed.split('/'); + var x = (frDate[2] + frDate[1] + frDate[0]) * 1; + } else { + x = 10000000; // = l'an 1000 ... + } + return x; + }, + + "date-euro-asc": function(a, b) { + return a - b; + }, + + "date-euro-desc": function(a, b) { + return b - a; + }, + + // datetime-euro column sorter + "datetime-euro-pre": function(a) { + var trimmed = $.trim(a); + if (trimmed != '') { + var frDateTime = trimmed.split(' - '); + var frDate= frDateTime[0].split('/'); + var frTime = frDateTime[1].split(':'); + var x = (frDate[2] + frDate[1] + frDate[0] + frTime[0] + frTime[1]) * 1; + } else { + x = 100000000000; // = l'an 1000 ... + } + return x; + }, + + "datetime-euro-asc": function(a, b) { + return a - b; + }, + + "datetime-euro-desc": function(a, b) { + return b - a; + } + }); + + + /** * Bootstrap style pagination control */ $.extend($.fn.dataTableExt.oPagination, { diff -r 7b6902a80d29 -r 8337e31c9edb src/pyams_skin/resources/js/myams-dataTables.min.js --- a/src/pyams_skin/resources/js/myams-dataTables.min.js Wed Oct 07 18:03:25 2015 +0200 +++ b/src/pyams_skin/resources/js/myams-dataTables.min.js Wed Oct 07 18:04:03 2015 +0200 @@ -1,1 +1,1 @@ -(function(b){b.extend(true,b.fn.dataTable.defaults,{sDom:"R<'dt-top-row'CLF>r<'dt-wrapper't><'dt-row dt-bottom-row'<'row'<'col-sm-6'i><'col-sm-6 text-right'p>>",sPaginationType:"bootstrap",oLanguage:{sLengthMenu:"_MENU_",sSearch:"_INPUT_"}});b.extend(b.fn.dataTableExt.oStdClasses,{sWrapper:"dataTables_wrapper form-inline"});b.fn.dataTableExt.oApi.fnPagingInfo=function(d){return{iStart:d._iDisplayStart,iEnd:d.fnDisplayEnd(),iLength:d._iDisplayLength,iTotal:d.fnRecordsTotal(),iFilteredTotal:d.fnRecordsDisplay(),iPage:d._iDisplayLength===-1?0:Math.ceil(d._iDisplayStart/d._iDisplayLength),iTotalPages:d._iDisplayLength===-1?0:Math.ceil(d.fnRecordsDisplay()/d._iDisplayLength)}};b.extend(b.fn.dataTableExt.oPagination,{bootstrap:{fnInit:function(h,e,g){var d=h.oLanguage.oPaginate;var i=function(j){j.preventDefault();if(h.oApi._fnPageChange(h,j.data.action)){g(h)}};b(e).append('");var f=b("a",e);b(f[0]).on("click.DT",{action:"previous"},i);b(f[1]).on("click.DT",{action:"next"},i)},fnUpdate:function(f,o){var p=5;var k=f.oInstance.fnPagingInfo();var n=f.aanFeatures.p;var m,l,h,d,q,g,e=Math.floor(p/2);if(k.iTotalPages=(k.iTotalPages-e)){d=k.iTotalPages-p+1;q=k.iTotalPages}else{d=k.iPage-e+1;q=d+p-1}}}for(m=0,g=n.length;m'+l+"").insertBefore(b("li:last",n[m])[0]).on("click",function(i){i.preventDefault();f._iDisplayStart=(parseInt(b("a",this).text(),10)-1)*k.iLength;o(f)})}if(k.iPage===0){b("li:first",n[m]).addClass("disabled")}else{b("li:first",n[m]).removeClass("disabled")}if(k.iPage===k.iTotalPages-1||k.iTotalPages===0){b("li:last",n[m]).addClass("disabled")}else{b("li:last",n[m]).removeClass("disabled")}}}}});b.extend(b.fn.dataTableExt.oPagination,{bootstrap_full:{fnInit:function(h,e,g){var d=h.oLanguage.oPaginate;var i=function(j){j.preventDefault();if(h.oApi._fnPageChange(h,j.data.action)){g(h)}};b(e).append('");var f=b("a",e);b(f[0]).on("click.DT",{action:"first"},i);b(f[1]).on("click.DT",{action:"previous"},i);b(f[2]).on("click.DT",{action:"next"},i);b(f[3]).on("click.DT",{action:"last"},i)},fnUpdate:function(f,o){var p=5;var k=f.oInstance.fnPagingInfo();var n=f.aanFeatures.p;var m,l,h,d,g,q,e=Math.floor(p/2);if(k.iTotalPages=(k.iTotalPages-e)){d=k.iTotalPages-p+1;q=k.iTotalPages}else{d=k.iPage-e+1;q=d+p-1}}}for(m=0,g=n.length;m'+l+"").insertBefore(b("li.next",n[m])[0]).on("click",function(i){i.preventDefault();f._iDisplayStart=(parseInt(b("a",this).text(),10)-1)*k.iLength;o(f)})}if(k.iPage===0){b("li.first",n[m]).addClass("disabled");b("li.prev",n[m]).addClass("disabled")}else{b("li.prev",n[m]).removeClass("disabled");b("li.first",n[m]).removeClass("disabled")}if(k.iPage===k.iTotalPages-1||k.iTotalPages===0){b("li.last",n[m]).addClass("disabled");b("li.next",n[m]).addClass("disabled")}else{b("li.next",n[m]).removeClass("disabled");b("li.last",n[m]).removeClass("disabled")}}}}});b.extend(b.fn.dataTableExt.oPagination,{bootstrap_prevnext:{fnInit:function(h,e,g){var d=h.oLanguage.oPaginate;var i=function(j){j.preventDefault();if(h.oApi._fnPageChange(h,j.data.action)){g(h)}};b(e).append('
');var f=b("a",e);b(f[0]).on("click.DT",{action:"first"},i);b(f[1]).on("click.DT",{action:"previous"},i);b(f[2]).on("click.DT",{action:"next"},i);b(f[3]).on("click.DT",{action:"last"},i)},fnUpdate:function(f,o){var p=5;var k=f.oInstance.fnPagingInfo();var n=f.aanFeatures.p;var m,l,h,d,q,g,e=Math.floor(p/2);if(k.iTotalPages=(k.iTotalPages-e)){d=k.iTotalPages-p+1;q=k.iTotalPages}else{d=k.iPage-e+1;q=d+p-1}}}for(m=0,g=n.length;m').attr("name",j);var k,h;var m=g.aLengthMenu;if(m.length==2&&typeof(m[0])=="object"&&typeof(m[1])=="object"){for(k=0,h=m[0].length;k").attr("value",m[0][k]).text(m[1][k]).appendTo(l)}}else{for(k=0,h=m.length;k").attr("value",m[k]).text(m[k]).appendTo(l)}}var p=f("
").addClass(g.oClasses.sLength).append(f("").addClass("ams-form").append(f("").addClass("select").css("width",60).append(l).append(f(""))));if(!g.aanFeatures.L){p.attr("id",g.sTableId+"_length")}this.dom.wrapper=p.get(0);f('select option[value="'+g._iDisplayLength+'"]',p).attr("selected",true);f("select",p).on("change.DT",function(i){var q=f(this).val();var r=g.aanFeatures.L;for(k=0,h=r.length;k").addClass(j.oClasses.sFilter).html('
'+l+"
");if(!j.aanFeatures.F){i.attr("id",j.sTableId+"_filter")}this.dom.wrapper=i.get(0);var k=f('input[type="text"]',i);i.data("DT_Input",k[0]);k.val(g.sSearch.replace('"',""")).addClass("form-control").attr("placeholder",j.oLanguage.sSearch).attr("aria-control",j.sTableId).on("keyup.DT",function(q){var s=j.aanFeatures.F;var r=f(this).val();for(var p=0,o=s.length;pr<'dt-wrapper't><'dt-row dt-bottom-row'<'row'<'col-sm-6'i><'col-sm-6 text-right'p>>",sPaginationType:"bootstrap",oLanguage:{sLengthMenu:"_MENU_",sSearch:"_INPUT_"}});b.extend(b.fn.dataTableExt.oStdClasses,{sWrapper:"dataTables_wrapper form-inline"});b.fn.dataTableExt.oApi.fnPagingInfo=function(d){return{iStart:d._iDisplayStart,iEnd:d.fnDisplayEnd(),iLength:d._iDisplayLength,iTotal:d.fnRecordsTotal(),iFilteredTotal:d.fnRecordsDisplay(),iPage:d._iDisplayLength===-1?0:Math.ceil(d._iDisplayStart/d._iDisplayLength),iTotalPages:d._iDisplayLength===-1?0:Math.ceil(d.fnRecordsDisplay()/d._iDisplayLength)}};b.fn.dataTableExt.aTypes.unshift(function(d){if(d!==null&&d.match(/^(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/[0-3][0-9]{3}$/)){return"date-euro"}return null});b.fn.dataTableExt.aTypes.unshift(function(d){if(d!==null&&d.match(/^(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/[0-3][0-9]{3} - ([0-1][0-9]|2[0-3]):[0-5][0-9]$/)){return"datetime-euro"}return null});b.extend(b.fn.dataTableExt.oSort,{"numeric-comma-asc":function(f,e){var d=f.replace(/,/,".").replace(/ /g,"");var g=e.replace(/,/,".").replace(/ /g,"");d=parseFloat(d);g=parseFloat(g);return((dg)?1:0))},"numeric-comma-desc":function(f,e){var d=f.replace(/,/,".").replace(/ /g,"");var g=e.replace(/,/,".").replace(/ /g,"");d=parseFloat(d);g=parseFloat(g);return((dg)?-1:0))},"date-euro-pre":function(f){var g=b.trim(f);if(g!=""){var e=g.split("/");var d=(e[2]+e[1]+e[0])*1}else{d=10000000}return d},"date-euro-asc":function(e,d){return e-d},"date-euro-desc":function(e,d){return d-e},"datetime-euro-pre":function(f){var i=b.trim(f);if(i!=""){var g=i.split(" - ");var e=g[0].split("/");var h=g[1].split(":");var d=(e[2]+e[1]+e[0]+h[0]+h[1])*1}else{d=100000000000}return d},"datetime-euro-asc":function(e,d){return e-d},"datetime-euro-desc":function(e,d){return d-e}});b.extend(b.fn.dataTableExt.oPagination,{bootstrap:{fnInit:function(h,e,g){var d=h.oLanguage.oPaginate;var i=function(j){j.preventDefault();if(h.oApi._fnPageChange(h,j.data.action)){g(h)}};b(e).append('");var f=b("a",e);b(f[0]).on("click.DT",{action:"previous"},i);b(f[1]).on("click.DT",{action:"next"},i)},fnUpdate:function(f,o){var p=5;var k=f.oInstance.fnPagingInfo();var n=f.aanFeatures.p;var m,l,h,d,q,g,e=Math.floor(p/2);if(k.iTotalPages=(k.iTotalPages-e)){d=k.iTotalPages-p+1;q=k.iTotalPages}else{d=k.iPage-e+1;q=d+p-1}}}for(m=0,g=n.length;m'+l+"").insertBefore(b("li:last",n[m])[0]).on("click",function(i){i.preventDefault();f._iDisplayStart=(parseInt(b("a",this).text(),10)-1)*k.iLength;o(f)})}if(k.iPage===0){b("li:first",n[m]).addClass("disabled")}else{b("li:first",n[m]).removeClass("disabled")}if(k.iPage===k.iTotalPages-1||k.iTotalPages===0){b("li:last",n[m]).addClass("disabled")}else{b("li:last",n[m]).removeClass("disabled")}}}}});b.extend(b.fn.dataTableExt.oPagination,{bootstrap_full:{fnInit:function(h,e,g){var d=h.oLanguage.oPaginate;var i=function(j){j.preventDefault();if(h.oApi._fnPageChange(h,j.data.action)){g(h)}};b(e).append('");var f=b("a",e);b(f[0]).on("click.DT",{action:"first"},i);b(f[1]).on("click.DT",{action:"previous"},i);b(f[2]).on("click.DT",{action:"next"},i);b(f[3]).on("click.DT",{action:"last"},i)},fnUpdate:function(f,o){var p=5;var k=f.oInstance.fnPagingInfo();var n=f.aanFeatures.p;var m,l,h,d,g,q,e=Math.floor(p/2);if(k.iTotalPages=(k.iTotalPages-e)){d=k.iTotalPages-p+1;q=k.iTotalPages}else{d=k.iPage-e+1;q=d+p-1}}}for(m=0,g=n.length;m'+l+"").insertBefore(b("li.next",n[m])[0]).on("click",function(i){i.preventDefault();f._iDisplayStart=(parseInt(b("a",this).text(),10)-1)*k.iLength;o(f)})}if(k.iPage===0){b("li.first",n[m]).addClass("disabled");b("li.prev",n[m]).addClass("disabled")}else{b("li.prev",n[m]).removeClass("disabled");b("li.first",n[m]).removeClass("disabled")}if(k.iPage===k.iTotalPages-1||k.iTotalPages===0){b("li.last",n[m]).addClass("disabled");b("li.next",n[m]).addClass("disabled")}else{b("li.next",n[m]).removeClass("disabled");b("li.last",n[m]).removeClass("disabled")}}}}});b.extend(b.fn.dataTableExt.oPagination,{bootstrap_prevnext:{fnInit:function(h,e,g){var d=h.oLanguage.oPaginate;var i=function(j){j.preventDefault();if(h.oApi._fnPageChange(h,j.data.action)){g(h)}};b(e).append('
');var f=b("a",e);b(f[0]).on("click.DT",{action:"first"},i);b(f[1]).on("click.DT",{action:"previous"},i);b(f[2]).on("click.DT",{action:"next"},i);b(f[3]).on("click.DT",{action:"last"},i)},fnUpdate:function(f,o){var p=5;var k=f.oInstance.fnPagingInfo();var n=f.aanFeatures.p;var m,l,h,d,q,g,e=Math.floor(p/2);if(k.iTotalPages=(k.iTotalPages-e)){d=k.iTotalPages-p+1;q=k.iTotalPages}else{d=k.iPage-e+1;q=d+p-1}}}for(m=0,g=n.length;m').attr("name",j);var k,h;var m=g.aLengthMenu;if(m.length==2&&typeof(m[0])=="object"&&typeof(m[1])=="object"){for(k=0,h=m[0].length;k").attr("value",m[0][k]).text(m[1][k]).appendTo(l)}}else{for(k=0,h=m.length;k").attr("value",m[k]).text(m[k]).appendTo(l)}}var p=f("
").addClass(g.oClasses.sLength).append(f("").addClass("ams-form").append(f("").addClass("select").css("width",60).append(l).append(f(""))));if(!g.aanFeatures.L){p.attr("id",g.sTableId+"_length")}this.dom.wrapper=p.get(0);f('select option[value="'+g._iDisplayLength+'"]',p).attr("selected",true);f("select",p).on("change.DT",function(i){var q=f(this).val();var r=g.aanFeatures.L;for(k=0,h=r.length;k").addClass(j.oClasses.sFilter).html('
'+l+"
");if(!j.aanFeatures.F){i.attr("id",j.sTableId+"_filter")}this.dom.wrapper=i.get(0);var k=f('input[type="text"]',i);i.data("DT_Input",k[0]);k.val(g.sSearch.replace('"',""")).addClass("form-control").attr("placeholder",j.oLanguage.sSearch).attr("aria-control",j.sTableId).on("keyup.DT",function(q){var s=j.aanFeatures.F;var r=f(this).val();for(var p=0,o=s.length;p