How to call JS Function

Is it possible to declare a comment and / or modify it by going through the OnCellModifiedOnAjax method of a GridWeb?

@lswe

If I am not mistaken, you want to add comment inside the GridCell from client-side function. We are afraid, it is not possible. But you can definitely do it on server side.

If you search on internet, you may find a solution to your problem. You could find some code that post a request on server via AJAX and execute your function on server side to accomplish your task.

My OnCellModifiedOnAjax method calls a server-side method.
I do my processing (add / modify) comment server side.
But the commentary of the cell does not update.
I do that in my page load :

       GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];
       foreach (GridCell cell in sheet.Cells)
       {
            GridComment comment = sheet.Comments[sheet.Comments.Add(cell.Name)];
            comment.Note = " ";
        }

And i do this in OnCellModifiedOnAjax :

    GridWorksheet sheet = GridWeb1.WorkSheets[worksheetState.ReportWorksheet.Name];
    GridComment comment = sheet.Comments[e.Cell.Name];
    if(comment != null)
         comment.Note = errorMessage;

@lswe,

Since you are updating cell’s comment in OnCellModifiedOnAjax, so you cannot get the updated comment on client side in Javascript. Well, you need to update the comment in the page (e.g Page_Load), so you can get the comment from client js code.

Thank you.

@lswe

We need to improve GridWeb as cell comment is not getting updated on client side when it gets updated on server side, so we have logged this issue in our database for improvement. We will look into it and fix this issue. Once, the issue is resolved or we have some other news for you, we will update you asap.

This issue has been logged as

  • CELLSNET-45554 - Synchronize or update the Comment in Client-side after Cell Comment is updated in Server-side

@lswe

Please download and try the latest fix and let us know your feedback. It fixes the issue CELLSNET-45554.

FYI:

The sample code for the issue: 

<script runat="server"> 
 protected void cellmodifiedserver(object sender, CellEventArgs e) 
    { 
        Console.WriteLine(e.Cell.StringValue); 
        GridWorksheet sheet = activities.WorkSheets[0]; 
        int i = sheet.Comments.Add(e.Cell.Name); 
        GridComment comment = sheet.Comments[i]; 
        comment.Note = "helloworld" + e.Cell.Name; 

    } 
</script> 
................... 
<script type="text/javascript" language="javascript"> 
        function clickcell(cell) { 
            var col = this.getCellColumn(cell); 
            var row = this.getCellRow(cell); 

            console.log("cell click " + " row:" + row + " ,col:" + col + " ," + this.getCellName(cell)); 
            var myformula = cell.getAttribute('formula'); 
            if (myformula != null) { 
                console.log("cell with formula :" + myformula); 

            } 
            else { 
                var value = this.getCellValueByCell(cell); 
                console.log("cell with value :" + value); 
            } 


        } 
        function cellupdated(cell) { 
            var col = this.getCellColumn(cell); 
            var row = this.getCellRow(cell); 

            console.log("cell updated " + " row:" + row + " ,col:" + col + " ," + this.getCellName(cell)); 
            var myformula = cell.getAttribute('formula'); 
            if (myformula != null) { 
                console.log("cell with formula :" + myformula); 

            } 
            else { 
                var value = this.getCellValueByCell(cell); 
                console.log("cell with value :" + value); 
            } 
            var comment = cell.getAttribute('CMNT'); 
            if (comment != null) { 
                 console.log("client side here:cell with comment :" + comment + ",author:" + cell.getAttribute('CMNT_AUTHOR')); 

            } 
        } 

</script> 
................................. 

<acw:gridweb ID="activities" runat="server" EnableAJAX="True" 
    OncellModifiedOnAjax="cellmodifiedserver" 
    OnCellSelectedClientFunction="clickcell" 
    OnCellUpdatedClientFunction="cellupdated" /> 

The expected behavior is: when user updated the cell comment on server side, we can get its value from client side 

Besides: in GridCell we added those methods just for convenience: 
  
/// Creates a comment object for a cell. 
public GridComment CreateComment(String note,String author,bool isvisible) 

/// Removes the comment object of the cell. 
public void RemoveComment() 

/// Get comment object on this cell 
public GridComment GetComment()

The issues you have found earlier (filed as CELLSNET-45554) have been fixed in latest version of Aspose.Cells for .NET (Download | NuGet).

We have to upgrade acwmain.js ?

@lswe,

Well, it is best that you should use the latest acwmain.js file from the latest Aspose.Cells.GridWeb v17.8.

can you give me a link to download the latest version?
thank you in advance

I have updated the .dll with version 17.8.0.
I did as explained above and the comment does not add up on my cell.

<acw:GridWeb ID="GridWeb1" runat="server" ShowLoading="true" PresetStyle="Standard"
     RenderHiddenRow="false" AutoFitColumn="true OnCellUpdatedClientFunction="onCellUpdated"
     XhtmlMode="true" Width="100%" Height="100%" OnCellModifiedOnAjax="GridWeb1_CellModifiedOnAjax"
     OnCellSelectedClientFunction="getContextForCell" EnableAsync="true"
     ShowUndoButton="false"howTabNavigation="false" ShowSaveButton="false" ShowSubmitButton="false"
     ShowLoadingPosition="true" OnCellClickOnAjax="WorksheetCellClickOnAjax" 
     OnCellSelectedAjaxCallBackClientFunction="OnCellSelectCallBack" EnableAJAX="true"> 
</acw:GridWeb>


 function onCellUpdated(cell) {
          var col = this.getCellColumn(cell);
          var row = this.getCellRow(cell);

         console.log("cell updated " + " row:" + row + " ,col:" + col + " ," + this.getCellName(cell));

         var cmnt = cell.getAttribute('CMNT');
         console.log("cmnt " + cmnt );
         if (cmnt != null) {
              ShowModalError("error", cmnt);
        }
  }

    protected void GridWeb1_CellModifiedOnAjax(object sender, CellEventArgs e)
    {
         GridWorksheet sheet = GridWeb1.WorkSheets[worksheetState.ReportWorksheet.Name];
         int i = sheet.Comments.Add(e.Cell.Name);
         GridComment comment = sheet.Comments[i];
         comment.Note = "Test Add " + e.Cell.Name;
   }

@lswe,

Please make sure you are using latest version of Aspose.Cells.GridWeb v17.8 with its resource files (in “\acw_client” folder @ your installation directory). Moreover, please refer to the code segment shared here:

If you still find the issue, kindly do create a sample project with Aspose.Cells.GridWeb v17.8, zip it and post us to reproduce the issue on our end, we will check it soon. Moreover, you may use any third party file sharing service (e.g dropbox, Google drive, etc.) to upload your sample project and share the Download link here.

Please can you give me the link for download the latest version of Aspose.Cells.GridWeb v17.8 with its resource files
Thank you

@lswe,

Please install Aspose.Cells for .NET v17.8 package using its MSI installer:
Aspose.Cells for .NET (Download | NuGet)

Now you will find Aspose.Cells.GridWeb v17.8 Dll with its resource files @ your installation directory.

I use the latest version of aspose.
And i cannot add a comment on my cell.
I have create a sample of our project.
You can download it on the link below :
https://1drv.ms/u/s!AvyGA5WCRAkDglJHNPTf3mXTmYkW
Thank you for you help

@lswe,

Thanks for the sample project.

I have run your project with Aspose.Cells.GridWeb v17.8, it works fine and adds the comment to to the first worksheet cell in the workbook, see the screenshot attached for your reference:
scshot_comments1.png (22.6 KB)

Ok the comment is add to the cell but i cannot get it in the cellupdated(cell) js method

function cellupdated(cell) {
        var col = this.getCellColumn(cell);
        var row = this.getCellRow(cell);

        console.log("cell updated " + " row:" + row + " ,col:" + col + " ," + this.getCellName(cell));
       
        var comment = cell.getAttribute('CMNT');
        if (comment != null) {
            console.log("client side here:cell with comment :" + comment + ",author:" + cell.getAttribute('CMNT_AUTHOR'));

        }
    }

@lswe,

You are right. I am able to observe the issue as you mentioned by using his sample code in the project. I found that comment is added to the cell on server side, but it is not retrieved on client side (Javascript). I checked the variable (for comment) which is always null.
e.g
Sample code:

........ 
<script type="text/javascript"> 

        function cellupdated(cell) { 
            var col = this.getCellColumn(cell); 
            var row = this.getCellRow(cell); 

            console.log("cell updated " + " row:" + row + " ,col:" + col + " ," + this.getCellName(cell)); 
            
            var cmnt = cell.getAttribute('CMNT'); 
            console.log("cmnt " + cmnt); 

           } 

    </script>
....... 

I have logged a ticket with an id “CELLSNET-45654” for your issue. We will look into soon.

Once we have an update on it, we will let you know here.

@lswe,

We did evaluate your issue further and found there was a mistake in the shared details (by us). Now we have extended GridComment. Basically, we have those attributes in the cell’s HTML node already:

  • CMNT_NOTE the basic comment note;

  • CMNT_AUTHOR the comment author;

  • CMNT_VISIBLE the visible of the comment

  • CMNT_W the width of the comment

  • CMNT_H the height of the comment
    so, you can use cell.getAttribute(‘CMNT_NOTE’) for your needs. See the updated code segment that works fine as I tested:
    e.g
    Sample code:

          function cellupdated(cell) { 
              var col = this.getCellColumn(cell); 
              var row = this.getCellRow(cell); 
    
              console.log("cell updated " + " row:" + row + " ,col:" + col + " ," + this.getCellName(cell)); 
              
              var cmnt = cell.getAttribute('CMNT_NOTE'); 
              console.log("cmnt " + cmnt); 
    
             } 
    
      </script>
    

Hope, this helps a bit.

The rest of the code (server side) don’t need to be change ?
I declare my GridComment like this ?

GridWorksheet sheet = GridWeb1.WorkSheets[0];
int i = sheet.Comments.Add(e.Cell.Name);
GridComment comment = sheet.Comments[i];
comment.Note = errorMessage + " " + e.Cell.Name;