RSS

Category Archives: JS Plugins

Customization of plugins

Sorting formatted numbers in jquery datatable

We can sort formated numbers in jquery data table. Here is the code. If we initialize our jquery data table by class ‘datatable’ and the 5th column contains formatted numbers data( comma separated numbers) then we can use the following code.

$(‘.datatable’).dataTable( {
“aoColumns”: [
null,
null,
null,
null,
{ “sType”: “formatted-num” }
]
});

jQuery.fn.dataTableExt.oSort[‘formatted-num-asc’] = function(a,b) {
/* Remove any formatting */
var x = a.match(/\d/) ? a.replace( /[^\d\-\.]/g, “” ) : 0;
var y = b.match(/\d/) ? b.replace( /[^\d\-\.]/g, “” ) : 0;

/* Parse and return */
return parseFloat(x) – parseFloat(y);
};

jQuery.fn.dataTableExt.oSort[‘formatted-num-desc’] = function(a,b) {
var x = a.match(/\d/) ? a.replace( /[^\d\-\.]/g, “” ) : 0;
var y = b.match(/\d/) ? b.replace( /[^\d\-\.]/g, “” ) : 0;

return parseFloat(y) – parseFloat(x);
};

 
Leave a comment

Posted by on May 11, 2012 in jQuery, JS Plugins

 

Tags: , ,

How do you move the close button to the top right corner in shadowbox 3.0+?

In the development process sometimes our client request us to use shadowbox to view larger image in popup box. Normaly the cross button placed at the bottom right of the box. But when we need to place the cross button at the top right corner then we can do it very easily by the following way.

Shadowbox.init({
onOpen: function() {
$(‘#sb-info’).after($(‘#sb-wrapper-inner’));
$(‘#sb-wrapper-inner’).after($(‘#sb-title’));
},
modal : true
});

 
2 Comments

Posted by on July 30, 2011 in JS Plugins