created dataTable add properties?
created dataTable add properties?
thiefyou
Posts: 14Questions: 0Answers: 0
I want created dataTable add properties..
//create dataTable
var _tmpTable = $("#sample").dataTable();
//add properties want
_tmpTable... ?
How can do it?
//create dataTable
var _tmpTable = $("#sample").dataTable();
//add properties want
_tmpTable... ?
How can do it?
This discussion has been closed.
Replies
[code]var _tmpTable = $("#sample").dataTable( {
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"bSort": false,
"bInfo": false,
"bAutoWidth": false
} );[/code]
http://www.datatables.net/release-datatables/examples/basic_init/filter_only.html
but I want add properties after initializing datatable.
How can do make initializing dataTable common function.
default properties contains initializing dataTable, but add properties
after initializing dataTable.
I'm not found dataTable's function.
/*
* initialize dataTable function
* oLocalTableNm : HTML TABLE Tag id property
* dtProps : JSON type dataTable properties
*/
function fnInitDataTable(oLocalTableNm, dtProps){
var props = { //default dataTable properties
"bDestroy" : true,
"iDisplayLength": 100,
"sDom": 'rt<"bottom">',
"bProcessing": true,
"bAutoWidth" : false,
"bDeferRender": true,
"bInfo": false,
"bLengthChange": false,
"bStateSave": false
}
var propsKey = []; //parsing dtProps Key
var propsVal = []; //parsing dtProps Value
$.each(dtProps,function(k,v){ //JSON data parsing and push the array variable
propsKey.push(k);
propsVal.push(v);
})
if(propsKey.length > 0 && propsVal.length > 0){
for(var i=0; i
I'm busy implementing this myself, but just to simplify things a little, here's what i came up with:
(Note that in my postInitApplyProperties function, i used $.extend(defaults, dtProps) instead of your method of pushing into arrays and all the unnecessary "ifs" and loops)
[code]
$(function(){
//here is the call to initialize all tables with class 'toDT' as a DataTable
DataTables.toDataTable($('table.toDT'));
// here is an example of a post-initialization property update, when the browser window is resized, resize the height of the DataTable
$(window).resize(function(){
DataTables.postInitApplyProperties(DataTables.getAllTablesInitializedAsDataTable(), { "sScrollY" : $(window).height() });
});
});
var DataTables = {
allDataTables: [],
isDataTable: function (nTable) {
var settings = $.fn.dataTableSettings;
for (var i = 0, iLen = settings.length; i < iLen; i++) {
if (settings[i].nTable == nTable) {
return true;
}
}
return false;
},
toDataTable: function (nTable) {
if ($(nTable) == null) {
return;
}
if ($(nTable).length > 1) {
for (var i = 0, iLen = nTable.length; i < iLen; i++) {
DataTables.toDataTable(nTable[i]);
}
return;
}
$(nTable).removeClass('toDT');
if (DataTables.isDataTable(nTable)) {
return;
}
var oTable = $(nTable).dataTable(DataTables.defaults);
DataTables.allDataTables.push(oTable);
},
defaults: {
"bPaginate": false,
"bLengthChange": true,
"bFilter": true,
"bInfo": true,
"bAutoWidth": true,
"bDestroy": true,
"bRetrieve": false,
"bJQueryUI": true,
"sScrollX": "100%",
"bScrollCollapse": true,
"sPaginationType": "full_numbers",
"bStateSave": false
},
postInitApplyProperties: function (nTable, dtProps) {
if ($(nTable) == null) {
return;
}
if ($(nTable).length > 1) {
for (var i = 0, iLen = nTable.length; i < iLen; i++) {
DataTables.postInitApplyProperties(nTable[i], dtProps);
}
return;
},
var settings = $.extend(DataTables.defaults, dtProps);
$(nTable).dataTable(settings);
},
getAllTablesInitializedAsDataTable: function () {
return STPDataTables.allDataTables;
}
};
[/code]