Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not override a column's formatter if already specified #11

Open
wants to merge 5 commits into
base: version2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/*
venv/
2 changes: 1 addition & 1 deletion css.min/datatable.bundle.min.css

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions js.min/datatable.bundle.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions js.min/datatable.min.js

Large diffs are not rendered by default.

184 changes: 96 additions & 88 deletions js/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,15 +1219,17 @@ jQuery( document ).ready(function() {
}

// Add default sorter for columns marked sortable
$(this.element).find('thead tr th[data-sortable="true"]').each(function(){
// Do not add a default sorter if one is already specified !
$(this.element).find('thead tr th[data-sortable="true"]:not([data-sorter])').each(function(){
window['valueSorter'+self.uniqueId] = function (a, b){
return self.valueSorter(a, b, 'asc');
};
$(this).attr('data-sorter', 'valueSorter'+self.uniqueId);
});

// Add default sorter for columns marked sortable
$(this.element).find('thead tr th[data-reversed="true"]').each(function(){
// Add default reverse sorter for columns marked sortable
// Do not add a default reverse sorter if one is already specified !
$(this.element).find('thead tr th[data-reversed="true"]:not([data-sorter])').each(function(){
window['valueSorterReverse'+self.uniqueId] = function (a, b){
return self.valueSorter(a, b, 'desc');
};
Expand Down Expand Up @@ -3960,98 +3962,104 @@ jQuery( document ).ready(function() {
$(this).attr('data-formatter', self.createInlineValueFormatter(value_type, index, $(that)));

}else{
switch(value_type){
case 'numeric-unit':
window['valueFormatter_numeric_unit'+self.uniqueId] = function (value, row, index){
if(jQuery.isNumeric(value)){
value = parseFloat(value);
return self.addNumberPrefix(value);

}else{
return value;
}
};

$(this).attr('data-formatter', 'valueFormatter_numeric_unit'+self.uniqueId);
break;

case 'html':
$(this).attr('data-formatter','valueFormatter_html');
break;
// If a data formatter is already specified, do not override it
if(! $(this).attr('data-formatter')){
switch(value_type){
case 'numeric-unit':
window['valueFormatter_numeric_unit'+self.uniqueId] = function (value, row, index){
if(jQuery.isNumeric(value)){
value = parseFloat(value);
return self.addNumberPrefix(value);

case 'date':
$(this).attr('data-formatter','valueFormatter_date');
break;

case 'list':
$(this).attr('data-formatter','valueFormatter_list');
break;

case 'url':
window['valueFormatter_url'+self.uniqueId] = function (value, row, index){
var links = [];
if(value.trim()){
var items = value.split(',');
if(items.length > 0){
for(var i=0;i<items.length;i++){
var current_link = items[i].trim();
var index = current_link.lastIndexOf(';');
if(index != -1){
var link = current_link.substring(0,index);
var link_title = current_link.substring(index+1);
links.push('<a class="datatable-link" href="' + link + '">'+link_title+'</a>');
}else{
links.push('<a class="datatable-icon" href="' + current_link + '">'+self.options.icon.url+'</a>');
}else{
return value;
}
};

$(this).attr('data-formatter', 'valueFormatter_numeric_unit'+self.uniqueId);
break;

case 'html':
$(this).attr('data-formatter','valueFormatter_html');
break;

case 'date':
$(this).attr('data-formatter','valueFormatter_date');
break;

case 'list':
$(this).attr('data-formatter','valueFormatter_list');
break;

case 'url':
window['valueFormatter_url'+self.uniqueId] = function (value, row, index){
var links = [];
if(value.trim()){
var items = value.split(',');
if(items.length > 0){
for(var i=0;i<items.length;i++){
var current_link = items[i].trim();
var index = current_link.lastIndexOf(';');
if(index != -1){
var link = current_link.substring(0,index);
var link_title = current_link.substring(index+1);
links.push('<a class="datatable-link" href="' + link + '">'+link_title+'</a>');
}else{
links.push('<a class="datatable-icon" href="' + current_link + '">'+self.options.icon.url+'</a>');
}
}
}
}
}
return links.join('<br>');
};
$(this).attr('data-formatter','valueFormatter_url'+self.uniqueId);
break;

case 'ref':
window['valueFormatter_ref'+self.uniqueId] = function (value, row, index){
var links = [];
if(value.trim()){
var items = value.split(',');
if(items.length > 0){
for(var i=0;i<items.length;i++){
var current_link = items[i].trim();
var index = current_link.lastIndexOf(';');
if(index != -1){
var link = current_link.substring(0,index);
var link_title = current_link.substring(index+1);
links.push('<a class="datatable-link" href="' + link + '">['+link_title+']</a>');
}else{
links.push('<a class="datatable-icon" href="' + current_link + '">'+self.options.icon.ref+'</a>');
return links.join('<br>');
};
$(this).attr('data-formatter','valueFormatter_url'+self.uniqueId);
break;

case 'ref':
window['valueFormatter_ref'+self.uniqueId] = function (value, row, index){
var links = [];
if(value.trim()){
var items = value.split(',');
if(items.length > 0){
for(var i=0;i<items.length;i++){
var current_link = items[i].trim();
var index = current_link.lastIndexOf(';');
if(index != -1){
var link = current_link.substring(0,index);
var link_title = current_link.substring(index+1);
links.push('<a class="datatable-link" href="' + link + '">['+link_title+']</a>');
}else{
links.push('<a class="datatable-icon" href="' + current_link + '">'+self.options.icon.ref+'</a>');
}
}
}
}
}
return links.join('<br>');
};
$(this).attr('data-formatter','valueFormatter_ref'+self.uniqueId);
break;

case 'anchor':
window['valueFormatter_anchor'+self.uniqueId] = function valueFormatter_anchor(value, row, index){
if(value.trim()){
return '<a class="datatable-icon" href="javascript:void(0)" onclick="$(\'#collapse-'+value+'\').collapse(\'show\');window.location.hash=\''+value+'\';return false;">'+self.options.icon.anchor+'</a>'
}else{
return value;
}
};
$(this).attr('data-formatter', 'valueFormatter_anchor'+self.uniqueId);
break;

default:
window['valueFormatter_hide'+self.uniqueId] = function (value, row, index){
return '<div class="text-muted" data-value="'+value+'">Invalid data-value-type</div>';
};
$(this).attr('data-formatter', 'valueFormatter_hide'+self.uniqueId);
break;
return links.join('<br>');
};
$(this).attr('data-formatter','valueFormatter_ref'+self.uniqueId);
break;

case 'anchor':
window['valueFormatter_anchor'+self.uniqueId] = function valueFormatter_anchor(value, row, index){
if(value.trim()){
return '<a class="datatable-icon" href="javascript:void(0)" onclick="$(\'#collapse-'+value+'\').collapse(\'show\');window.location.hash=\''+value+'\';return false;">'+self.options.icon.anchor+'</a>'
}else{
return value;
}
};
$(this).attr('data-formatter', 'valueFormatter_anchor'+self.uniqueId);
break;
case 'str':
// Allow the str data format to specify its own data formatter function
break;

default:
window['valueFormatter_hide'+self.uniqueId] = function (value, row, index){
return '<div class="text-muted" data-value="'+value+'">Invalid data-value-type</div>';
};
$(this).attr('data-formatter', 'valueFormatter_hide'+self.uniqueId);
break;
}
}
}
});
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rcssmin
jsmin