Search/Filter results export

Search/Filter results export

stepgrstepgr Posts: 13Questions: 3Answers: 0

Hi folks , this is not solely a datatables issue and pardon my ignorance I'm no
js expert .

I'm using grocerycrud together with codeigniter for some data input and processing. grocerycrud has a theme
that implements datatables together with tabletools . My problem is with an export button there is on
the page, you can filter/search whatever you want but when you hit the export button , you get back a
xls file with all the data not just the search results. Now I have tried various approaches I've seen here
searching the forums about similar problems but nothing seems to work in this case.

The datatables initialization is :

function loadDataTable(this_datatables) {
    return $(this_datatables).dataTable({
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        "bStateSave": use_storage,
        "fnStateSave": function (oSettings, oData) {
            localStorage.setItem( 'DataTables_' + unique_hash, JSON.stringify(oData) );
        },
        "fnStateLoad": function (oSettings) {
            return JSON.parse( localStorage.getItem('DataTables_'+unique_hash) );
        },
        "iDisplayLength": default_per_page,
        "aaSorting": datatables_aaSorting,
        "fnInitComplete" : function () {
            $('.DTTT_button_text').attr('download', '');
            $('.DTTT_button_text').attr('href', export_url);
        },
        "oLanguage":{
            "sProcessing":   list_loading,
            "sLengthMenu":   show_entries_string,
            "sZeroRecords":  list_no_items,
            "sInfo":         displaying_paging_string,
            "sInfoEmpty":   list_zero_entries,
            "sInfoFiltered": filtered_from_string,
            "sSearch":       search_string+":",
            "oPaginate": {
                "sFirst":    paging_first,
                "sPrevious": paging_previous,
                "sNext":     paging_next,
                "sLast":     paging_last
            }
        },
        "bDestory": true,
        "bRetrieve": true,
        "fnDrawCallback": function() {
            //If there is no thumbnail this means that the fancybox library doesn't exist
            if ($('.image-thumbnail').length > 0) {
                $('.image-thumbnail').fancybox({
                    'transitionIn': 'elastic',
                    'transitionOut': 'elastic',
                    'speedIn': 600,
                    'speedOut': 200,
                    'overlayShow': false
                });
            }
            add_edit_button_listener();
            $('.DTTT_button_text').attr('href', export_url);
        },
        "sDom": 'T<"clear"><"H"lfr>t<"F"ip>',
        "oTableTools": {
            "aButtons": aButtons,
            "sSwfPath": base_url+"assets/grocery_crud/themes/datatables/extras/TableTools/media/swf/copy_csv_xls_pdf.swf"
        }
    });
}

and the function for the document ready is below with my addition (commented now ) showing in the export aButtons :

$(document).ready(function() {

    $('table.groceryCrudTable thead tr th').each(function(index){
        if(!$(this).hasClass('actions'))
        {
            mColumns[index] = index;
        }
    });

    if(!unset_export)
    {
        aButtons.push({
            "sExtends":    "text",
            "sButtonText": export_text,
     //"oSelectorOpts": { filter: "applied", order: "current" }
        });
    }

    if(!unset_print)
    {
        aButtons.push({
             "sExtends":    "print",
             "sButtonText": print_text,
             "mColumns": mColumns
         });
    }

I down have any js experience besides basic things and I what I want to know is
is my addition wrong (as in oSelectorsOpts) ?
is there probably some additional step to make to get the filtered result set back ?

Thanks

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406

    That looks very unfamiliar to me to be honest. Most be some old syntax no longer in use when using "regular" data tables.

    Assuming the rest of your code works and your problem is limited to not being able to export the filtered rows as opposed to exporting all table rows which is working. So if the only amendment you made to the working code is "oSelectorOpts" then there is an obvious error: filter: "applied" should be replaced with order: "applied"
    https://datatables.net/reference/type/selector-modifier

    order: "current" is redundant because that is the default.

  • stepgrstepgr Posts: 13Questions: 3Answers: 0

    Thanks for your suggestion . I changed to :

    if(!unset_export)
        {
            aButtons.push({
                "sExtends":    "text",
                "sButtonText": export_text,
                            "oSelectorOpts": { order: "applied" }
            });
        }
    

    but same result
    The export works yes but it doesn't take into effect the search results.
    The syntax is old yes, I tried to convert to modern datatables (buttons + Select) but my knowledge in js is limited I'm afraid (it uses 1.9 vesrion as far as I know.
    Do you happen to know if I can view in console the filtered results (as in which array should have the filtered result set ) ?

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765

    The selector-modifier docs show the option to be search not filter. filter may be a legacy option. Try { search: 'applied' }. Not sure if that works with the old TabelTools extension though.

    Kevin

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406

    Yep, order: "applied" was bullshit, sorry. Of course it must be search: "applied" instead of filter: "applied".

  • stepgrstepgr Posts: 13Questions: 3Answers: 0

    Yeap it doesn't work either :

    if(!unset_export)
        {
            aButtons.push({
                "sExtends":    "text",
                "sButtonText": export_text,
                            "oSelectorOpts": { search: 'applied' }
            });
        }
    

    Well I'm out of ideas , probably something in this older version is different than the current version.

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406

    @allan might be able to help.

  • kthorngrenkthorngren Posts: 20,276Questions: 26Answers: 4,765

    Allan can state whether this feature is available with TableTools. Its a retired extension and I've never used it so don't know. The Buttons Extension is the current library for exporting data. Not sure if it works with Datatables 1.9. Have you considered upgrading to 1.10?

    Kevin

  • stepgrstepgr Posts: 13Questions: 3Answers: 0

    Looks I don't have an option here , I must find the way to upgrade the code to newer
    version and check , going to learn a bit more javascript !
    Thanks anyway guys !!

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406

    We're here to help out whenever you get stuck! Consider to get Editor as well if that works with what you do. Will make life a lot easier - that has been my experience - and the license is fairly inexpensive. My amortization period was about one working day ...

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    Yep, we'd strongly suggest updating to the most recent version. As you're finding out, knowledge of those older versions is limited, and support is focused on the current versions,

    Colin

This discussion has been closed.