Trying to add some html to a cell using javascript

Posted by: dustinaleksiuk on 8 September 2017, 8:40 am EST

    • Post Options:
    • Link

    Posted 8 September 2017, 8:40 am EST

    Hi folks,



    I need to be able to click a link on the spread, and toggle the link once clicked. When I create the new HTML and add it to the cell, it doesn’t work. Viewing source doesn’t seem to work for some reason also. I get a <a displayed, so it looks to me as if it’s truncating the text at the space.



    I couldn’t escape the HTML properly, but I know it looks OK because I can display it in an alert properly. On the server side I call SaveChanges() to get this to initialize properly.







    function toggleValue(rowIndex)

    {

       var value = spreadControl.GetValue(rowIndex, 2);

       var htmlString;



       if(value < 0)

       {

          htmlString = ‘the html’

       }

       else if(value >= 0)

       {

          htmlString = ‘the html’

       } 



       spreadControl.SetValue(rowIndex, 1, htmlString);

    }





     




    Any help would be greately appreciated. We’re going to buy the spread if we can just do a few simple proof of concept things.



    Regards,

    Dustin Aleksiuk

  • Posted 8 September 2017, 8:40 am EST

    Dustin,



    I am not sure what you are trying to do here. It almost sounds like you are trying to put HTML in the cell. If that is correct you need to set the EncodeValue property of the Spread to False. If this is not what you are doing, could you attach a small zipped project reproducing the problem you are seeing for us to debug?

  • Posted 8 September 2017, 8:40 am EST

    Thanks for your reply. I apologise for my terrible explanation. Busy day yesterday. I'll explain better below, and if I have to send some code I will. Pretty easy to replicate though.



    All I'm trying to do is set the value of a cell to some HTML, but on the client side using the SetValue(row, col, value) Javascript function.



    The behaviour I want is to have a link which toggles back and forth between 'buy' and 'sell' when clicked. Thing is, I can't post back. It has to be very fast.

    I can set up the link on the server by calling EncodeValue on the server as you said, but then on the client it won't let me set the values of the cells to the new HTML.



    I have a simple javascript function which gets called when you click the link. It calls the SetValue(row, col, value) Farpoint Javascript function to set the new HTML into the cell. When I try to set the value I only see the <a part of the A tag in the cell.



    I can imagine that this is a security feature so people can't inject malicious code into an editable cell.



    As I eagerly await your reply, I'm looking at three different options for doing this:

    1. Try to somehow get a HyperLink type of cell to work

    2. Using some kind of custom celltype with it's own painters.

    3. Possibly walking the DOM tree manually and finding the cell. I doubt this will work with the Farpoint grid, and it's ugly anyway.



    As a side note, I did a proof of concept using the standard .NET datagrid, but we really want the rich functionality of the Farpoint one. I got the datagrid one to work by using SetAttribute on the cell to set an ID which I could get grab by using the Javascript DOM functions. Pretty crappy way to do it, I think.



    Thanks very much,

    Dustin Aleksiuk

  • Posted 8 September 2017, 8:40 am EST

    Problem solved. I had to make a custom cell type and a custom .htc file with my own SetValue method. Then I could do this:



    element.innerHTML = value;



    instead of:



    element.innerText = value;



    which is apparently the default.



    Thanks for your help. I kind of wish there was a bit more background info on creating a htc file in the client side scripting documentation, but overall the docs have been really good.



    Regards,

    Dustin Aleksiuk



  • Posted 16 May 2018, 4:18 am EST

    Apologies for asking this on a similar thread but I have am need of some help along the same lines. I’m needing add text to a cell but within this text each word may have a hyperlink action associated with it to different page.

    Eg. Client A (* “Go to Client A

    ); Client B (* “Go to Client B

    )

    I tried returning all the html markup from my stored proc but the cell is just diplaying all my html. If I double click the cell to edit, it properly formats the hyperlink without displaying the href and parameter tags. I’m not sure if this requires a custom cell type or if i’m just missing an out of the box cell type property to display the content as html. Thoughts?

    I’ve also tried the hyperlink cell type but this doesn’t work for different links within the cell.

Need extra support?

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

Learn More

Forum Channels