Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.fn.dataTableExt.aoFeatures.push change setting

I have below code

$.fn.dataTableExt.aoFeatures.push({
    "fnInit": function (oSettings) {
        oSettings.oScroll.sY = 5;
        return  { "oSettings":  oSettings } ;
      },
    "cFeature": "T"
});

$.extend($.fn.dataTable.defaults, {
       //"scrollY": 5,
       "dom":"T"
    });

I can see scrollY changed in function but no effect in datatable, How can overwrite the default setting using this function, since i have to put condition ono tableid,

otherwise I could have done below way which is working

 $.extend($.fn.dataTable.defaults, {
           "scrollY": 5,

        });

I believe I am missing something on return statement which will override the things

fiddle reference

like image 266
Md. Parvez Alam Avatar asked Sep 04 '26 08:09

Md. Parvez Alam


1 Answers

You code is not working for a few reasons. First, you are using an outdated API. $.fn.dataTableExt.aoFeatures.push is the old API used with $(...).dataTable(). By using $(...).DataTable() (note the capital "D") as you did in your fiddle, you are choosing to use the new API. (Read about converting code using the old API to use the new API here.) Using the current API is a great choice, but you then need to use $.fn.dataTable.ext.feature.push to set up your feature.

This works:

$.fn.dataTable.ext.feature.push({
    "fnInit": function (settings) {
        settings.oScroll.sY = 25;
      },
    "cFeature": "T"
});

However, the dom feature is intended to indicate the order of elements in the table. Using it to set style like scrollY is OK, but not exactly what they had in mind. The point being that if you are going to specify dom at all, you have to specify all the elements you want. In particular, you have to specify t for table or else the DataTable will not attach itself to the table at all. So you need to set up your table with something like this to trigger your scrollY "feature":

$(document).ready(function() {
    var table = $('#example').DataTable({
        "dom":"Tlftip"
    });

Note that the order matters. The "T" has to come before the other elements that are affected by the changes made in the feature. "dom":"lftipT" will not have the desired effect.

like image 190
Old Pro Avatar answered Sep 05 '26 21:09

Old Pro