Export grid to CSV with selectionmode listbox

Posted by: son on 1 July 2021, 2:15 am EST

    • Post Options:
    • Link

    Posted 1 July 2021, 2:15 am EST

    Dear,

    I’m doing an export all data in grid to CSV file.

    With default selectionmode the sample code works fine.

    But when I switch to selectionmode listbox only export selected row (ie CellRange has no effect).

    Sample Code: https://www.grapecity.com/wijmo/docs/Topics/Grid/ImportExport/Export-To-Excel-CSV

    Please help me export all data with listbox mode

    Thanks,

  • Posted 1 July 2021, 10:46 pm EST

    Hi,

    The code in the above link does not work when selectionMode is set to ListBox because the selection property of FlexGrid works only when the selection done is contiguous, unlike ListBox where we can select non-contiguous rows by Ctrl+Clicking.

    Thus, we may have to provide custom implementation by performing the following:

    • “We may make use of the selectedRows property of FlexGrid which gets/sets the array containing the rows that are currently selected.”

    • “We may manually create cellRange for each row and append the data which we will get through the getClipString() method of FlexGrid.”

    Regards,

    Manish Gupta

    FlexGrid_Selection_ExportCSV.zip

  • Posted 2 July 2021, 1:29 am EST

    Hi Manish Gupta

    Thanks for your information.

    Your example helps me to understand Flexgird better, but this is not my case yet.

    My case is that I want to export all rows in the grid, regardless of whether it is selected or not.

    Do you have any more suggestions for me?

    Thanks

  • Posted 4 July 2021, 5:06 pm EST

    Hi Son,

    The following code retrieves the complete FlexGrid data and export it as CSV.

    var rng = new wijmo.grid.CellRange(0, 0, theGrid.rows.length - 1, theGrid.columns.length - 1);
    var csvData = theGrid.getClipString(rng, true, true);
    

    Here is the demo sample for your reference.

    Regards,

    Manish Gupta

    FlexGrd_Export_CSV.zip

  • Posted 6 July 2021, 11:30 pm EST

    Hi Manish Gupta

    Your example is exactly what I was looking for. But when applying to my project, it only exports selected rows.

    I think the problem is in my project and I will have to find the cause.

    Thank you for your help

  • Posted 7 July 2021, 1:30 pm EST

    Hi,

    Thank you for confirming that the sample is working as per your expectation. Please investigate and let us know when you have any further information and needed any help.

    Regards,

    Manish Gupta

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels