Change table cell value/content when clicked

Description: Changing the contents of a selected cell within a table

What MCU/Processor/Board and compiler are you using? ESP_IDF using ESP32S3 TFT parallel w/ touch 3.5

What LVGL version are you using? V8.3

What do you want to achieve? I want to change the cell value or contents when the user clicks that certain cell.

What have you tried so far? I know it is related to an event callback, I have created the table and it is able to be clicked. The Biggest issue I am having is understanding lv_table_get_selected_cell(). I do not know where the event would get the row or column that is selected. AKA i do not know what to put as parameters other than the table.

note: i feel like this is way simplier than I am making it to be but I have looked through the forums and examples and can’t seem to find anything.
Ultimate goal: get the clicked cell and change its contents

Code to reproduce

static void create_bit_table(lv_obj_t* parent)
{

    lv_obj_t* screen = lv_obj_create(parent);
     // Create the table
    lv_obj_t* table = lv_table_create(screen);
    lv_table_set_col_cnt(table, 1);  // Single column: Bit State 0

    // Set the cell values from the table data
    for (uint16_t i = 0; i < sizeof(tableData) / sizeof(tableData[0]); i++) {
        lv_table_set_cell_value(table, i, 0, tableData[i]);
    }

     // Set the cell values from the table data
    for (uint16_t i = 0; i < sizeof(tableData) / sizeof(tableData[0]); i++) {
        lv_table_set_cell_value(table, i, 0, tableData[i]);  // Initial state: Bit State 0
        //lv_table_set_cell_align(table, i, 0, LV_LABEL_ALIGN_LEFT);  // Align cell content to the left
    }

    lv_obj_add_event_cb(table, tableEventHandler_2, LV_EVENT_CLICKED, NULL);

}
const char* tableData[] = {
    "Generator Not in OFF",
    "Generator Not in MANUAL",
    "Generator Switched to AUTO",
    "Generator Stopped *",
    "Not On Generator Power",
    "Cranking Volts OK",
    "Battery Charger Test OK",
    "Battery Voltage High Alarm Test OK",
    "Battery Voltage Low Alarm Test OK",
    "Coolant Temp High Warning Test OK",
    "Coolant Temp Low Test OK",
    "Coolant Temp High Test OK",
    "Oil Pressure Low Warning Test OK",
    "Oil Pressure Low Shutdown Test OK",
    "Emergency Stop Test OK",
    "Over Crank Test OK",
    "Over Speed Test OK",
    "Fuel Level Low Warning Test OK",
    "Fuel Level Low Shutdown Test OK",
    "Coolant Level Low Warning Test OK",
    "Coolant Level Low ShutdownTest OK"
};
// DOES NOT WORK, this is where the problem lies. 
// Table event handler
 void tableEventHandler_2(lv_event_t * event)
{
    lv_obj_t* table = lv_event_get_target(event);
    lv_event_code_t code = lv_event_get_code(event);
    //lv_obj_draw_part_dsc_t	*dsc = lv_event_get_draw_part_dsc(event);
    uint8_t* cellData = (uint8_t*)lv_event_get_user_data(event);

    if(code == LV_EVENT_CLICKED)
    {
        // idk what to put as param below
        lv_obj_t* selected = lv_table_get_selected_cell(table, , 0)

        // change cell value
        // not worried about this part yet, just want to get selected cell
    }
}

So… I am an idiot. The param row and col in lv_table_get_selected_cell() is what it returns/stores the values in rather than asking for it to find the cell. I’ll leave this up since someone might find it useful. How to use :
uint16_t row, col;
lv_table_get_selected_cell(table,&row,&col);

Now you have the row and col from the table that is selected/pressed

1 Like