Common utility method for creating a datatable

Common utility method for creating a datatable

sudheer6291sudheer6291 Posts: 5Questions: 1Answers: 0

Hi Allan,

We have nearly 30 datatables in our application.We need to write the the datatable code snippet every where so we thought of writing a common function which will help every time when calling the datatable. I want unable to loop inside aoColumns to set the column related values i am able to set all other parameters.Can you please help me out allan regarding this issue.

Hoping a quick response.

Thanks in Advance

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Please post your code and a link to a test case. Also, I'm delighted to help write code if you require, with the DataTables support options.

    Allan

  • sudheer6291sudheer6291 Posts: 5Questions: 1Answers: 0
    edited May 2014
    /*
     * tableId - id given for the table in HTML
     * tableName - Name given to the table for further operations
     * processing(boolean)- should be set to make the processing false
     * retrieve(boolean) - if we want to retrieve our datatable faster we should make this true
     * paginate(boolean) - if we want to paginate please make this true
     * lengthChange(boolean) - if we dont want to show the length change we should make it false
     * info(boolean)- if we dont want to show info of the entries make it false
     * autoWidth(boolean) - If we dont want to have auto width set make it false
     * needInitComplete(boolean) - if we want to execute some thing after initialization of datatable
     * needRowCallBack(boolean) - if we want to use row call back in our table
     * tableColumns - array of json objects
     */
    
    
    function commonDataTable(tableId,tableName,processing,retrieve,paginate,
    lengthChange,info,autoWidth,deferRender,needInitComplete,needRowCallBack,tableColumns){
        //alert('Inside commonDataTable --> '+tableColumns)
        alert(tableName)
        window.testTableName=tableName;
        testTableName= $("#"+tableId).dataTable({
                        "bProcessing": processing,
                        "bRetrieve"  : retrieve,
                         "bPaginate" : paginate,
                         "bLengthChange": lengthChange,
                         "bInfo": info,
                         "bAutoWidth" : autoWidth,
                         "bDeferRender": deferRender,
                         "aoColumns": tableColumns,
                         "fnInitComplete": function(){
                             if(needInitComplete){
                                 //alert("Table initialization with id  "+tableId+" is complated");
                             }
                         },
                        "fnRowCallback" : function(nRow, aData, iDisplayIndex){
                            
                         }
                        
                    });
    }
    

    This is the function what i'm trying to write for creating the datatables. by calling this method. By specifying all the parameters required in the method call.

    Please help me out whether my approach is fine.

    Will I be able to perform operations on datatables created of this sort.

    Thanks in advance

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Looks okay to me. Personally I'd pass in an object as it is far more extensible (in the same way that DataTables uses an object, rather than 100+ parameters).

    Allan

  • sudheer6291sudheer6291 Posts: 5Questions: 1Answers: 0
    edited May 2014

    yeah that's a great idea i would do that TQ.

    But can we perform operations on datatables created in this way?

    Row selection with out using table tools etc...

    Thanks for the Reply

    Sudheer

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I don't see why you wouldn't be able to.

    Allan

This discussion has been closed.