unable to copy all records while using copy button (not of tabletools)?

unable to copy all records while using copy button (not of tabletools)?

stsh3011stsh3011 Posts: 11Questions: 4Answers: 0

I am not able to copy all records of datatable i am populating using ajax.Button copies only displayed records by default to clipboard and formatted records but not all.Please help me to sort out this issue? have gone through but not found any proper solution that i require.
Thanks in advance

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    Sounds like you are running into this FAQ. Are you using server-side processing (with out a link to a test case, which is required in the forum rules, it is impossible for us to say).

    Allan

  • stsh3011stsh3011 Posts: 11Questions: 4Answers: 0
    edited January 2016

    Thank you Mr. Allan for your quick reply. I am implementing this on my local for custom needs of a wordpress plugin using server side true, so currently not able to provide the link but will try for this and problem is while am copying using copyHtml5 button i want whole records should copy but only displayed once get copied and i also tried to change buttonshtml5.js but not get overcome.Hope you have been getting my trouble. I have fetched my data using ajax and my datatable header is not fixed.Hope i have cleared you about.

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Answer ✓

    I understand the issue and would encourage you to read the FAQ that I linked to above. As it states, copying of all rows when using server-side processing is not currently possible.

    Allan

  • stsh3011stsh3011 Posts: 11Questions: 4Answers: 0

    Again Thanks for quick reply, i have gone through the faqs and got the point but if i want to then can it be possible by modifying the buttonHtml5.js or by any other programmatic way.Please guide

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    No. The client-side only has access to the displayed records. It obviously can't output more than it has.

    You would either need to load all the data to the client-side or have the server create the file.

    Allan

  • stsh3011stsh3011 Posts: 11Questions: 4Answers: 0
    edited January 2016

    ok i have fetched all records that i need using ajax call from like for pdf or csv export then how can i pass this data to clip board top copy

    l.ext.buttons.copyHtml5 = {
            
            className: "buttons-copy buttons-html5",
            text: function (a) {
                return a.i18n("buttons.copy", "Copy")
            },
            //action: function (a, b, d, c) {
                action: function (a, b, d, c) {
                
                    for (var key in b.context[0].aLastSort) {  // Get Last Sort column order and column name 
                    var column = b.context[0].aLastSort[key].col;
                    var order = b.context[0].aLastSort[key].dir;
                }
                var searchvalue = b.context[0].oPreviousSearch.sSearch;  // Get Last Search value 
    
              
               $.ajax({
                    "serverSide": true,
                    url: ajax_object.ajaxurl,
                    //url: 'scripts/server_processing.php',
                    data: {action: '_ajax_datatable',id:getid(),searchvalue: searchvalue, exportbutton: 'true', column: column, ordertype: order},
                    method: 'POST',
                    sync: true
                }).success(function(dd){
                data=JSON.parse(dd);
                var xy=new Array();
                i=0;
                $.each(data.data, function (r, record) {
                        
                         xy[i++] = String(record).split(",");
                       
    //                    $.each(array, function (key, value) {
    //                        line += '"' + value + '",';
    //                    });
    //                    line = line.slice(0, -1);
    //                    a += line + '\n';
                    });
    
    a = B((xy),c);  // this is where i am passing ajax call response to b but there is formatting problem i think ```
    ..........
    

    and where function B is like

    B = function (a,b) {
                    
                    for (var e = u(b), c = a.buttons.exportData(b.exportOptions) , d = b.fieldBoundary, h = b.fieldSeparator,
                            f = RegExp(d, "g"), g = b.escapeChar !== k ? b.escapeChar : "\\", i = function (a) {
                        for (var b = "", c = 0, e = a.length; c < e; c++)
                            0 < c && (b += h), b += d ? d + ("" + a[c]).replace(f, g + d) + d : a[c];
                        return b
                    }, n = b.header ? i(c.header) + e : "", j = b.footer ? e + i(c.footer) : "", l = [], m = 0, o = c.body.length; m < o; m++)
                        l.push(i(c.body[m]));
                    return {
                        str: n + l.join(e) + j,
                        rows: l.length
                    }
    
                }, 
    

    Hope i made you clear, Please guide me ....

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    If I understand correctly, you've added code to the copy button to get all rows and then want to export them? If you are doing that, then why not just load all records up front?

    My suggestion is to either load all up front, or have the server load them.

    Having said that, I'd be happy to write a plug-in for you under the datatables support options that does what you need.

  • stsh3011stsh3011 Posts: 11Questions: 4Answers: 0

    Thanks again Mr. Allan, i am at middle to get this whatever you said and i dont want to display all records at once without pagination means if i select length to display records as All then datatable (default) copy works very well thats what i want with any of the length i select. i am playing with buttonHtml5.js and getting the data but not able to copy on clipboard i.e. f.execCommand("copy"); returns false when i pass my data as sting from function B(a,b) that return b as output.

    Sorry for keeping the discussion long because not cleared.Hope i'll get my solution in your next guidance.

  • stsh3011stsh3011 Posts: 11Questions: 4Answers: 0

    thank you for all your assistance provided

This discussion has been closed.