← Back to Docs
  • index.html
  • Clayground
  • Clayground.Text
  • CsvModel
  • Clayground 2025.2
  • CsvModel QML Type

    High-level component combining CSV reading/writing with a TableModel. More...

    Import Statement: import Clayground.Text

    Detailed Description

    CsvModel provides a convenient way to load CSV data into a Qt TableModel for display in views, and to save modified data back to CSV format. It supports filtering columns and rows, as well as transforming row data.

    Example usage:

    import Clayground.Text
    
    CsvModel {
        id: gameData
        source: "enemies.csv"
        colFilter: (name) => ["id", "type", "health"].includes(name)
        rowFilter: (vals) => parseInt(vals[2]) > 50
    
        Component.onCompleted: load()
    }

    Properties

    CSV file path or data to read.

    Delimiter character for reading CSV (default: ",").

    Function to filter columns: (colName) => bool. Return true to include the column, false to exclude it.

    Function to filter rows: (rowVals) => bool. Return true to include the row, false to exclude it.

    Function to transform row data: (rowVals) => array. Modify and return the row values array.

    File path for saving CSV data.

    Delimiter character for writing CSV (default: ",").

    The generated TableModel containing loaded data. Use this property to bind to TableView or other model-based views.

    Array of column names from the CSV header.

    Methods

    Loads CSV data from the source into the tableModel.

    Saves the current tableModel data to the destination file.