how disable ng2 smart table row selection

Discussão em 'Angular' iniciado por Anjana Dep, Novembro 27, 2024.

  1. Anjana Dep

    Anjana Dep Guest

    This is my tableSettings

    getSafetyTableSettings() {
    this.settingsSafety = {
    hideSubHeader: true,
    actions: false,
    selectMode:'multi',
    noDataMessage: this.translate.instant('stressCheck.implPlan.table.noDataMessage'),
    pager: false,
    rowClassFunction: (row) => {
    return {
    'disabled-row': this.isRowDisabled(row)
    };
    },
    columns: {


    And in here i disable the checkboxes like this

    isRowDisabled(row) {
    // Assuming your data is in this.surverData.payload
    // and you want to check the previous row's endedDateTime
    const index = this.surverData?.payload?.findIndex(item => item === row);

    if (index > 0) {
    const previousRow = this.surverData.payload[index - 1];
    return previousRow.endedDateTime
    && moment(previousRow.endedDateTime).isBefore(moment());
    }

    return false;
    }


    I want to disable the row selection in the ngx-data-table also at the same time how do i do it ?

    this is onRowSelect event for you refernce

    onRowSelect(event) {
    const rowData = event.data;
    const rowIndex = this.surverData?.payload.findIndex(item => item.refId === rowData.refId);
    const isCheckboxDisabled = rowIndex !== -1 &&
    this.surverData.payload[rowIndex].endedDateTime &&
    moment(this.surverData.payload[rowIndex].endedDateTime).isBefore(moment());

    if (isCheckboxDisabled) {
    event.isSelected = false;
    event.selected = event.selected.filter(row => row.refId !== rowData.refId);
    } else if (event.isSelected) {
    this.selectedRows = event.selected.filter(row => !row.disabled);
    }
    this.resendPopButton = (this.selectedRows && this.selectedRows.length > 0);
    console.log(" ~ StatusListMainComponent ~ onRowSelect ~ event:", event);
    console.log(" ~ Selected Rows:", this.selectedRows);
    }


    }


    I tried multipes things but non worked

    Continue reading...

Compartilhe esta Página