How to call JS Function

Hello,

We have a GridWeb and we would like to call a server side JS function at the end of the modification of a cell.
How can we do that?

Thank you for your help.

@lswe,

Thanks for your query.

Please see the documents in the section on how to read, write or use client side Javascript functions in GridWeb for your reference:

Thank you.

Hello, thank you for your answer.
I will present my question differently.
We have a server-side processing that gives us a certain result.
We go through the gridweb’s “OnCellModifiedOnAjax” method.
The result is a string.
We would like to retrieve this string from the client side.
Is it possible to include it as an attribute of the “cell” object and if so how to recover it on the client side?

@lswe,

We think you can try OnCellUpdatedClientFunction, see the sample code for your reference:
e.g
Sample code:

<acw:gridweb ID="activities" runat="server" EnableAJAX="True" 
    OncellModifiedOnAjax="cellmodifiedserver" 
    OnCellSelectedClientFunction="clickcell"
    OnCellUpdatedClientFunction="cellupdated"  />
 <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);
            }
            

        }
        
        

    </script>

Thank you.

OK
But I lose my cell value.
We assigned server-side a value to the cell .
The formula overwrites the value.
How I can do to pass my string and keep the assigned value ?

@lswe,

Could you provide us a simple sample project (runnable) to show the issue, we will check it soon. Also provide complete details/steps with screenshots to reproduce the issue on our end, we may log a ticket for it.

Thank you.

Hello,
You do not have a single attribute that does not affect the cell.
For example a comment?
cordially

@lswe,

If you need to get comment (for the cell) on the client side(Javascript), you may try the following sample code:
e.g
Sample code:

var mycomment = cell.getAttribute(‘cmnt’);

Hope, this helps a bit.

Thank you.

How do I declare the ‘cmnt’ attribute on the server side to retrieve it from the client side?

@lswe,

We have server side GridComment class to access or manipulate the comment on the cell, you will simply add comment to the cell on server side. See the document for your reference:

Thank you.

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