Datatables column have toggle icons. How can i perform export to excel with values like 1 or 0.

Datatables column have toggle icons. How can i perform export to excel with values like 1 or 0.

mohit951mohit951 Posts: 7Questions: 2Answers: 0

I am using datatables wherein status icon is used. I want to get values in export to excel as 1 and 0. Currently, it is showing as blank values.

How can i customize ?

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,169Questions: 26Answers: 4,922
    Answer ✓

    Your code will need to update the data for that column with the values of 1 or 0. Similar to what the rowCallback function is doing in this example. Are you doing something like this?

    Kevin

  • mohit951mohit951 Posts: 7Questions: 2Answers: 0
    edited March 2020

    It is basically custom icons. What I want is during excel export, values should appear based on it.
    Above one is also correct, but how to perform the same during excel export. ?

  • kthorngrenkthorngren Posts: 21,169Questions: 26Answers: 4,922

    Like I said you need to update the Datatables data to have the values of 1 or 0 depending on the position of the toggle. Please build a simple test case showing what you have then we can help you get this going.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • mohit951mohit951 Posts: 7Questions: 2Answers: 0
    edited March 2020

    I have achieved this with the below code. You have rightly guided me.

         ****customize: function ( xlsx ) {
                         //update Row
                        var sheet = xlsx.xl.worksheets['sheet1.xml'];
                        var clRow = $('row', sheet);
    
                        var status_values = $('tbody').find('tr').find('td');
                        let status_vals     =   [];
                        status_values.each(function () {
    
                            if($(this).prop("checked")){
                                status_vals.push(1);
                            }else{
                                status_vals.push(0);
                            }
                        });
                        let colid = 1;
                        let i = 0;
                        clRow.each(function () {
                            if(colid!=1){
                                let html =  $(this)[0].innerHTML;
                                html    =   html+'<c t="inlineStr" r="D'+colid+'"><is><t>'+status_vals[i++]+'</t></is></c>';
                                $(this)[0].innerHTML = html;
                            }
                            colid++;
                        });
        }****
    

    Thanks Kevin for your help.

  • kthorngrenkthorngren Posts: 21,169Questions: 26Answers: 4,922
    Answer ✓

    Glad you got it working but that is not exactly what I had in mind. Here is an example of what I meant:
    http://live.datatables.net/muxexejo/1/edit

    To add to my above comment this solution also needs to use orthogonal data for the export as shown in this example. Just showing this example for others that might find this thread. If your solution works for you please continue to use it.

    Kevin

This discussion has been closed.