created dataTable add properties?

created dataTable add properties?

thiefyouthiefyou Posts: 14Questions: 0Answers: 0
edited November 2011 in DataTables 1.8
I want created dataTable add properties..

//create dataTable
var _tmpTable = $("#sample").dataTable();

//add properties want
_tmpTable... ?

How can do it?

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    You can add properties to the datatable by passing in an initialization object at creation time

    [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
  • thiefyouthiefyou Posts: 14Questions: 0Answers: 0
    thanks..

    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.
  • thiefyouthiefyou Posts: 14Questions: 0Answers: 0
    I got it!

    /*
    * 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
  • GavinvanGentGavinvanGent Posts: 2Questions: 0Answers: 0
    edited August 2012
    My First post on DataTables, and am loving it so far. Its been in my hands for the last two days and have been met with some issues, but finding my way around nicely. Good job to Allan and team (i'm assuming Allan is working with a team??).

    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]
This discussion has been closed.