"fnSetColumnVis" method is not working with the server side proccessing of datatable

"fnSetColumnVis" method is not working with the server side proccessing of datatable

VineethVineeth Posts: 11Questions: 3Answers: 0
edited August 2015 in Free community support

Hi,

I had generated grid with datatable server side processing enabled.When i use this method "fnSetColumnVis" to hide some columns after the datatable is generated it making a post to ajax request.Is there any other way to acheive the functionality,
please let me know

Answers

  • allanallan Posts: 63,361Questions: 1Answers: 10,448 Site admin

    Per the forum rules, please link to a test case showing the issue.

    Allan

  • VineethVineeth Posts: 11Questions: 3Answers: 0
    edited August 2015

    Hi,

    <script type="text/javascript>
    
    var oTable;
    
    $(document).ready(function() {
    
    var columns = [{"mDataProp":"Number"},{"mDataProp":"Name"},{"mDataProp":"Date"}];
    
    oTable=$('#ajaxDatatable').dataTable({
                            "bProcessing": true,
                            "bServerSide": true,
                            "sAjaxSource": "Home/GetDatat",
                            "fnServerParams": function (aoData) {
                                aoData.push({ "name": "Namefilter", "value": $("#Namefilter").val() });
                            },
                            "sServerMethod": "post",
                            "pageLength": 10,
                            "aoColumns":columns
                          
                        });
    
    var showIndex=[1,2];
    
    for(var i = 0; i < showIndex.length; i++) {
    var iCol = parseInt(array[i]);
     oTable.fnSetColumnVis(iCol, false);
    }
    
    });
    
    </sctript>
    

    while executing this oTable.fnSetColumnVis(iCol, false); it is again posting the ajax url "Home/GetDatat".how i can i acheive the hide functionality on the above scenario?

    Thanks,

    Vineeth

  • allanallan Posts: 63,361Questions: 1Answers: 10,448 Site admin

    Use the new API - column().visible() rather than the legacy API to achieve what you want.

    Allan

  • VineethVineeth Posts: 11Questions: 3Answers: 0
    edited August 2015

    hi allan,

    I had downloaded the latest datatable js (1.10.7) and then used as you guided,

    var iCol = parseInt(1);
    
    var otable=$('#ajaxDatatable).datatable();
     oTable.column(iCol).visible(true);
    

    but it is throwing error as follows,
    TypeError: oTable.column is not a function

  • allanallan Posts: 63,361Questions: 1Answers: 10,448 Site admin

    See the second top FAQ.

    Allan

  • VineethVineeth Posts: 11Questions: 3Answers: 0
    edited August 2015

    hi allan,

    i had checked with the minium and full version of the latest datable.js

    /*! DataTables 1.10.7
     * ©2008-2014 SpryMedia Ltd - datatables.net/license
     */
    
    /**
     * @summary     DataTables
     * @description Paginate, search and order HTML tables
     * @version     1.10.7
     * @file        jquery.dataTables.js
     * @author      SpryMedia Ltd (www.sprymedia.co.uk)
     * @contact     www.sprymedia.co.uk/contact
     * @copyright   Copyright 2008-2014 SpryMedia Ltd.
    

    But still i am not able to call this method.Error as follows,

    "TypeError: oTable.column is not a function

    oTable.column(iCol).visible(true)"
    

    Initalization part as follows,

    var oTable;
     oTable=$('#ajaxDatatable').dataTable({
                            "bProcessing": true,
                            "bServerSide": true,
                            "sAjaxSource": document.URL,
                            "fnServerParams": function (aoData) {
                                aoData.push({ "name": "OrganizationNamefilter", "value": $("#OrganizationNamefilter").val() });
                                aoData.push({ "name": "CountryID", "value": $("#CountryID").val() });
                                aoData.push({ "name": "StateID", "value": $("#StateID").val() });
                                aoData.push({ "name": "CityID", "value": $("#CityID").val() });
                                aoData.push({ "name": "OrganizationTypeID", "value": $("#OrganizationTypeID").val() });
                                aoData.push({ "name": "StatusID", "value": $("#StatusID").val() });
                            },
                            "sServerMethod": "post",
                            "pageLength": 10,
                            "aoColumns":columns
                        });
    
  • allanallan Posts: 63,361Questions: 1Answers: 10,448 Site admin

    I'd suggest reading that FAQ again :-)

    Change:

    oTable=$('#ajaxDatatable').dataTable({

    To:

    oTable=$('#ajaxDatatable').DataTable({

    Note the capital D.

    Allan

  • VineethVineeth Posts: 11Questions: 3Answers: 0

    Hi allan,

    Thats worked now i am able to use this new api method.Thanks :)

This discussion has been closed.