Deferred Loading and TableTools

Deferred Loading and TableTools

DarkenspiritDarkenspirit Posts: 48Questions: 11Answers: 0
edited June 2014 in Free community support

I referenced this before but I need a new workaround now.

As of right now if you use deferredloading with table tools, the export buttons and copy button only copies what you have loaded. So right now i have default view to show 10 rows per page. When you hit Copy, despite having the settings to copy all. It will only copy 10. Then if you go to page 2. and hit copy again, it will copy 20.

If you set deferred loading to false, then the buttons will get all entries.

Is there a fix for this?

            {
                "sExtends": "copy",
                "bSelectedOnly": true,
        "mColumns": "visible"
            },

my old thread http://datatables.net/forums/discussion/21218/weird-export-thing-going-on-with-tabletools-and-ajax-data#latest

This question has an accepted answers - jump to answer

Answers

  • DaharkDahark Posts: 28Questions: 1Answers: 0

    Hey Darkenspirit,

    I am using deferredRender and the Export function exports all the Data from my table.

    What does your DataTable Setup look like? I tried to replicate your TableTools Setup, but I couldn't get the Problem you are having...

    Kind Regards

  • DarkenspiritDarkenspirit Posts: 48Questions: 11Answers: 0

    http://datatables.net/forums/discussion/comment/62060/

    http://live.datatables.net/conefim/5

    Here is the live datatable example. If you click Copy, it only copies the first 10. If you load page 2 then hit copy. it copies 20 now. Its only copying what has been loaded by the looks of it. If you jump to page 6 then and hit copy again. it only copies page 1,2 and 6

  • DaharkDahark Posts: 28Questions: 1Answers: 0

    Hey Darkenspirit,

    question:
    Why do you extend the Copy Function?

    "aButtons": [
                    {
                        "sExtends": "copy",
                        "fnClick": function ( nButton, oConfig, flash ) {
                            this.fnSetText( flash, this.fnGetTableData(oConfig) );
                        }
                    }
                ]
    

    Can you try just this:

            "aButtons": [
                    "copy"
                ]
    

    My configuration for the copy Button is just like this and it copys all the Data in the Table without any further configuration or action.
    In your Live example I have the Problem, it doesn't copy anything at all, but I'm currently not on my own PC so this could be a client Problem.

    Please give it a try or update me why you are extending the default copy function.

    Kind Regards

  • DarkenspiritDarkenspirit Posts: 48Questions: 11Answers: 0
    edited June 2014

    Hi, Sorry for the slow update.

    My actual table which has this issue extends copy, xls and csv with these params.

    This lets me extract only what the user selects. Maybe that is the issue? Maybe I just cant have this feature, if I changed it to just export all regardless of what the user chooses. If thats the case I need to also remove the select feature.

                "aButtons": [
                    {
                        "sExtends": "copy",
                        "bSelectedOnly": true,
                        "mColumns": "visible"
                    },
                    {
                        "sExtends": "csv",
                        "bSelectedOnly": true,
                        "mColumns": "all"
                    },
                    {
                        "sExtends": "xls",
                        "bSelectedOnly": true,
                        "mColumns": "all"
                    },
                    {
                    "sExtends":    "select_all",
                    "sButtonText": "Select Filtered",
                    "fnClick": function (nButton, oConfig, oFlash) {                                                  
                    var oTT = TableTools.fnGetInstance('table_1');
                    oTT.fnSelectAll(true); //True = Select only filtered rows (true). Optional - default false.
                        }
                    },
                    {
                        "sExtends": "select_none",
                        "mColumns": "visible"
                    }
                ],
    
  • DaharkDahark Posts: 28Questions: 1Answers: 0
    edited June 2014

    Hi,

    I don't quite get it. What do you want to export? Only the rows the user selected, or the complete Table including the rows that are hidden by pagination?

    Or do you mean, selected columns?

  • DarkenspiritDarkenspirit Posts: 48Questions: 11Answers: 0

    bSelectedOnly
    When this option is set to true, the data gathered from the table will be from only the rows which are selected by the end user (using the sRowSelect option) - all other data will be discarded (i.e. not used in the save / copy). If no rows are selected, then all data is used.

    mColumns
    This parameters defines which columns should be used as the data source for the export. The parameter can either be a string with a value of 'all', 'visible', 'hidden' or 'sortable' - or an array of integers with the column indexes to be exported.

    This means if the user filters out columns, they wont get them. Likewise if they filter out things using the filtering I have setup, they can hit the select all button and export only what they have filtered. Lets say they filter to find one column to only show things from PA. If they hit the export without anything selected, it was exporting everything. With this setting, they can hit select all button after filtering and export only those rows particularly. Its a work around really.

  • DaharkDahark Posts: 28Questions: 1Answers: 0

    Okay, I understand what you're doing.
    I have a similar Setup. But I am loading the data dynamicly into an object and then feeding it to dataTables.
    It works how I set it up, but if I try to transfer my setup on to your test case, it still fails. I have tried different Versions of jQuery, tabletools, different browsers. I even hardcoded the Data and wrote it to an object (similar to my setup), but it still doesn't behave the way it should...
    I'll have another look later on and maybe I can find out what is so much different in my setup that it works with my tables es it should.

  • DarkenspiritDarkenspirit Posts: 48Questions: 11Answers: 0

    My data comes from 2 ajax calls that I use javascript to concat together as a global variable. Data tables then initalizes with this global variable as it's data source. This isnt a problem since I've had this copy issue with deferred loading back when i was just using a single ajax call that datatables itself made to get the data.

    function loadTable() {
            var table = $('#table_1').dataTable( {
                "data" : jsonTop,
                "columns": [
                    { "data": "policyid"},
                    { "data": "policytxnid"},
                    { "data": "pol submission no"},
                    { "data": "txn submission no"},
                ],
                "dom": 'TC<"clear">lfrtipS',
                "tableTools": {
                    "sRowSelect": "multi",
                    "aButtons": [
                        {
                            "sExtends": "copy",
                            "bSelectedOnly": true,
                            "mColumns": "visible"
                        },
                        {
                            "sExtends": "csv",
                            "bSelectedOnly": true,
                            "mColumns": "all"
                        },
                        {
                            "sExtends": "xls",
                            "bSelectedOnly": true,
                            "mColumns": "all"
                        },
                        {
                        "sExtends":    "select_all",
                        "sButtonText": "Select Filtered",
                        "fnClick": function (nButton, oConfig, oFlash) {                                                  
                        var oTT = TableTools.fnGetInstance('table_1');
                        oTT.fnSelectAll(true); //True = Select only filtered rows (true). Optional - default false.
                            }
                        },
                        {
                            "sExtends": "select_none",
                            "mColumns": "visible"
                        }
                    ],
                    "sSwfPath": "swf/copy_csv_xls.swf"
                },
                "colVis": {
                    exclude: [ 0 ]
                },
                "scrollX": true,
                "scrollY": "440px",
                "scrollCollapse": true,
                "autowidth": true,
                "info": true,
                "iDisplayLength": 10,
                "ServerSide": false,
                "deferRender": true
            } )
                .columnFilter();
    };
    
  • DaharkDahark Posts: 28Questions: 1Answers: 0

    My Data comes from SharePoint and the Data is loaded otherwise.
    But eventually it doesn't mather, cause I could reproduce the problem you're having even when I hardcode the Data as an object in Javascript. Everything get's loaded correctly, but the Copy function just doesn't do what it is supposed to do.

  • csgjbeckcsgjbeck Posts: 8Questions: 2Answers: 1
    edited July 2014

    I am having the same problem. I did some digging in the code and inside dataTables.tableTools.js the function "_fnGetDataTablesData" is where the export will grab it's data.

    I had the bright idea that I could just force a call to fnSelectAll() to select all rows before I export, but that didn't work.

    The problem is that dt.aoData[] will only be loaded with as many rows as pagination tells it too. Even though it's length will be right, the dt.aoData[index].nTr will be null when index > pagination.

    dt.aoData[] comes from jQuery.dataTables.js, I'll have to look in there as to how to load aoData[] fully on request at the top of "_fnGetDataTablesData"

  • DarkenspiritDarkenspirit Posts: 48Questions: 11Answers: 0
    edited July 2014

    http://datatables.net/forums/discussion/21723/getting-tn-4-error-only-in-internet-explorer#Comment_62547

    Allan has responded saying they will fix the issue but its too far back on the list. When I need it fixed, I will probably pay for the support if its not fixed by then.

    See this response from him:

    allan July 5
    Hi,

    I mentioned that I would be trying to fix it last week and I would post back if I did get a chance to fix it. However, for various reasons I didn't get a chance to do so and haven't updated the thread. I'll post back there when I do get a chance to do so.

    Allan

  • csgjbeckcsgjbeck Posts: 8Questions: 2Answers: 1
    Answer ✓

    Hey, this is now fixed (as of 7/15/14).

    Allan says, "This issue should actually fixed in the versions of DataTables and TableTools that was released yesterday (1.10.1 and 2.2.2 respective).

    Could you possibly try updating to the new releases, and I think this issue should simply vanish ( http://datatables.net/download )."

This discussion has been closed.