How can I set default setting value?
How can I set default setting value?
Hello.
I use this plugin all over my site, but most initialize parameters are duplicated like this.
Example #1
[code]
$('#dt_example').dataTable( {
"sAjaxSource": ''aaaa.php'
, "aaSorting": [[ 0, "desc" ]]
, "bStateSave": true
, "sPaginationType": "full_numbers"
, "bJQueryUI": true
, "oLanguage" : {
"sUrl": '/p/back/js/languages/ja_JP.txt'
}
});
[/code]
Example #2
[code]
$('#dt_example').dataTable( {
"sAjaxSource": ''bbb.php'
, "aaSorting": [[ 2, "desc" ]]
, "bStateSave": true
, "sPaginationType": "full_numbers"
, "bJQueryUI": true
, "oLanguage" : {
"sUrl": '/p/back/js/languages/ja_JP.txt'
}
});
[/code]
I'd like to avoid coding same setting each time.
jQuery UI can be changed default setting value like following.
[code]
jQuery.ui.dialog.defaults.modal = true;
jQuery.ui.dialog.defaults.bgiframe = true;
jQuery.ui.dialog.defaults.resizable = true;
jQuery.ui.dialog.defaults.width = 400;
[/code]
I hope DataTables has same function like jQuery UI.
I use this plugin all over my site, but most initialize parameters are duplicated like this.
Example #1
[code]
$('#dt_example').dataTable( {
"sAjaxSource": ''aaaa.php'
, "aaSorting": [[ 0, "desc" ]]
, "bStateSave": true
, "sPaginationType": "full_numbers"
, "bJQueryUI": true
, "oLanguage" : {
"sUrl": '/p/back/js/languages/ja_JP.txt'
}
});
[/code]
Example #2
[code]
$('#dt_example').dataTable( {
"sAjaxSource": ''bbb.php'
, "aaSorting": [[ 2, "desc" ]]
, "bStateSave": true
, "sPaginationType": "full_numbers"
, "bJQueryUI": true
, "oLanguage" : {
"sUrl": '/p/back/js/languages/ja_JP.txt'
}
});
[/code]
I'd like to avoid coding same setting each time.
jQuery UI can be changed default setting value like following.
[code]
jQuery.ui.dialog.defaults.modal = true;
jQuery.ui.dialog.defaults.bgiframe = true;
jQuery.ui.dialog.defaults.resizable = true;
jQuery.ui.dialog.defaults.width = 400;
[/code]
I hope DataTables has same function like jQuery UI.
This discussion has been closed.
Replies
Regards,
Allan
I've checked http://datatables.net/forums/comments.php?DiscussionID=1285.
I dont' wanna disturb original source code as well so I'd like to take approach #2. However, the #2 doesn't look nice for me comparing to the jQuery UI's. Could you give me a example code for me plase?
[code]
var oDefault = {
"bFilter": false,
"bSort": false
};
var oST = $.extend( true, {}, oDefault );
oST.bFilter = true;
$('#example').dataTable( oST );
[/code]
This would have sorting disabled, but filtering enabled.
It might not be as nice as the jQuery UI option, but to be honest, I hadn't actually considered this particular set up! You could stick the default object somewhere in your source files, so it doesn't need to be quite as ugly as I have above...
Regards,
Allan
All right...
The code is not enough smart for me. I'd rather re-write original source code and set default values.
Thank you again, Allan.
[code]
var oDefault = {
"bFilter": false,
"bSort": false
};
$('#example').dataTable( $.extend( true, {}, oDefault, {
"bFilter": true
} ) );
[/code]
The first parameter as 'true' isn't really needed in this case, but it would be if you were using aoColumns etc. But if you would rather alter the original source, that is a just as effective a solution :-)
I'll have a think about other options to change the default parameters, but I suspect most of them would probably require about the same amount of code as this :-).
Regards,
Allan
I took a look around the original source code and tried to separate default option value, it seems a large amount of modifications.