How To Disable (ReadOnly) Single Cell

Posted by: curiosichi on 16 April 2018, 2:31 am EST

    • Post Options:
    • Link

    Posted 16 April 2018, 2:31 am EST

    I have multiple databound sheets in a workbook, and adding the below event handler causes the cell to be disabled on all sheets. (every sheet’s row 1 col 1 is frozen).

    
    
    flexSheet.beginningEdit.addHandler(function (sender, e) {
        if (e.row === 1 && e.col === 1) {
            e.cancel = true;
         }
    });
    
    
    

    Is there not a better way to do this than a handler on the whole grid? Can it be tied to the individual worksheet? As you can imagine, freezing every cell of the workbook is not my intention.

    The below works to make a column read only (DOES NOT WORK FOR ROW) on a particular sheet (just set the active sheet before setting the read only). Can a similar attribute be added to a cell and row?

    
    
    // references FlexSheet named 'ServerWorkbook' in the view
    @ViewChild('ServerWorkbook') ServerWorkbook: wjcGridSheet.FlexSheet;
    
    // stuff . . . then when applying formats on a per sheet Index:
    
    this.ServerWorkbook.sheets.selectedIndex = sheetIndex;
    
    this.ServerWorkbook.sheets[sheetIndex].grid.columns[8].isReadOnly = true;
    
    
    
  • Posted 16 April 2018, 9:20 pm EST

    Hi,

    For making a read-only cell, handling beginningEdit event is the only option currently available.

    For making cells of a particular sheet read-only you can compare the sheetIndex with selectedSheetIndex.

    //refer to following code snippet
    flexSheet.beginningEdit.addHandler((s,e)=>{
    if(s.selectedSheetIndex==1&&e.row==2&&e.col==2){
    e.cancel=true;
    }
    });
    

    In reference to read-only row problem

    It appears to be an issue,I’ve asked the dev team to look into it (317676).

    Till then you can use the following workaround to make a row read-only:-

    
    flexSheet.selectedSheetChanged.addHandler((s,e)=>{
    //make row with index 2 read only for sheet 1
    if(s.selectedSheetIndex==1){
    flexSheet.rows[2].isReadOnly=true; 
    }
    });
    

    ~nilay

  • Posted 17 April 2018, 6:04 am EST

    Thanks for confirming the issue with row Nilay.

    I look forward to the resolution to ticket #317676 and perhaps a feature request of individual cells having a read only attribute as well.

    Please update me with an ETA or completion of this issue so I can issue the proper fix when it is deployed.

    Thanks again!

  • Posted 17 April 2018, 11:04 pm EST

    Hi,

    The issue is with dev team.

    We will let you know as we get any update on this.

    ~Manish

  • Posted 22 May 2018, 3:52 am EST

    Is there an update on this issue?

  • Posted 22 May 2018, 6:32 pm EST

    Hi,

    We are sorry for the delayed response.

    The issue has been fixed in the latest build 5.20181.462. Please find the updated sample:

    https://stackblitz.com/edit/angular-qyjw7r?file=app/app.component.ts

    ~Manish

  • Posted 16 October 2018, 9:12 am EST - Updated 3 October 2022, 11:20 am EST

    Any chance I can submit a feature request for a read only attribute on a cell instead of having to manage handlers?

    Or do you have a suggestion (or example) of how I can easily format this grid in flexsheet? Making one row or column all read only is not adequate, and complete rows and columns can’t have the styles applied the same because only a subset of rows/columns share the same style.

    Lets add another thing to consider: My grids are dynamically created, so I apply a style based on the contents of the column or row. I have some very inefficient attempts at looping through every column and row and applying styles one by one, but with a 30 sheet flexsheet, with 100s of rows/ dozens of columns each, individual functions applied dynamically, and handlers, the initialization takes 10-20 seconds.

    Imagine the grid might load with 10 columns, or might load with 20 columns. I cant hard code the style, the read only handler, ect. It has to be dynamic. The only thing I know at run time is data in the grid (I can search for column header = “1”) and style based on header content (if Header = “1”, apply these style to row 1-10.)

    Oh, but then every 10-20 rows there is a total row across the whole grid. I need to then make that row read only and calculate the columns’ row’s values.

    But the first 3 columns of that row are part of the row headers (need to be read only), so they get styled differently.

    Its pretty complex eh? There must be a better way to style and apply functions dynamically.

  • Posted 16 October 2018, 5:47 pm EST

    We have created an enhancement request to add support for read-only cells(Internal tracking Id: 348526). It might be implemented in the future releases if found feasible.

    For conditional styling, you may handle the formatItem event and format the cells as required.

    Please refer to the following sample which demonstrates the same: https://stackblitz.com/edit/angular-uq3g2w?file=styles.css

    However heavy processing in formatItem handler may lead to some performance degrade, so try to keep processing in formatItem handler as min as possible.

    ~Sharad

Need extra support?

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

Learn More

Forum Channels