Export to excel not working for multiple excel downloads

Export to excel not working for multiple excel downloads

minhalminhal Posts: 76Questions: 12Answers: 0

I am looking to create multiple excel files on a single click. It seems to be working for a single column but I am looking to do it while exporting the data from 3 columns with or condition.

Here is the link for my example
http://live.datatables.net/jipucijo/1/edit

I have set the data in the above example based on the "System Architect" position which lies in position 1, position 2 and position 3. What I am trying to do is to make use of the OR condition where if "System Architect" lies in either of the 3 columns (position 1, position 2 and position 3), to export all the data from these columns where the value lies.

Answers

  • minhalminhal Posts: 76Questions: 12Answers: 0

    Here is my working example for one column which does multiple downloads.

    http://live.datatables.net/guhowefo/1/edit

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited July 2019

    Just a quick glance you have this:

                  column = dt.column(0);  // column contains API for column 0
                  column = dt.column(1);  // column contains API for column 1
                  column = dt.column(2);  // column contains API for column 2
    

    The variable column will only contain the API for column 2. If you want column to contain all 3 columns then try column = dt.columns( [0,1,2] );. Not sure if this will give the results you want but you can try it.

    Kevin

  • minhalminhal Posts: 76Questions: 12Answers: 0

    Hi @kthorngren ,

    I did the way you suggest but the create excel button is still not working.

    Here is the link to my example
    http://live.datatables.net/mesopacu/1/edit

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    edited July 2019

    You have a syntax error. Try changing dt.cells(null, 0,1,2, { to dt.cells(null, [0,1,2], {. This will make 1,2,3 and array.

    Kevin

  • minhalminhal Posts: 76Questions: 12Answers: 0
    edited July 2019

    @kthorngren ,

    Thanks I got it right now and the create to excel button is working. However its returning empty files now with no data. I think what it's doing is it's returning the values from columns 0,1,2 while using AND search. I am looking to use OR search so that it returns all values.

    Here is the link to my example now:
    http://live.datatables.net/mesopacu/2/edit

  • minhalminhal Posts: 76Questions: 12Answers: 0

    @kthorngren ,

    Please see the example below:
    http://live.datatables.net/gituqahe/1/edit

    I have tried to do it by different ways but still not able to get the data still getting the empty file. Your response is highly appreciated.

    Thanks

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736

    You will probably need to create a search plugin to handle the OR searches across multiple columns. I don't have a specific example for what you are doing but do have a couple you can start from.

    My first suggestion is to use a global variable as a flag to determine if the plugin should run. Set the flag true if the button is clicked. Otherwise for normal searches set the flag false. Basically in your button's action function you will have the following steps:

    1. Set global variable true
    2. Use dt.draw() to run the search plugin
    3. Execute the excelHtml5.action.call
    4. Set the global variable false
    5. Use dt.draw() to revert the table back to what the use expects to see

    Here is an example of using the flag:
    http://live.datatables.net/yisaqore/1/edit

    Just replace this code with an if that checks the flag:

          // Return all rows if search is blank
          if (val === '') {
            return true;
          }
    

    This is a example of using an OR search across columns:
    http://live.datatables.net/mucevape/1/edit

    Hope this helps.

    Kevin

This discussion has been closed.