Author Topic: How to make a href in a cell?  (Read 3050 times)

gmswsd

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 40
    • View Profile
How to make a href in a cell?
« on: March 30, 2020, 10:23:28 am »
Does this grid allow for clickable cells.
<a href="https://www.nba.com">NBA Basketball</a>
I could not find any examples of this.
Could you provide and example?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: How to make a href in a cell?
« Reply #1 on: March 30, 2020, 10:49:54 am »
Any html including <a href=""></a> can be rendered in the cells with column.render callback.

Code: [Select]
column.render = function( ui ){
 return "<a href='test.html'>" + ui.cellData + "</a>";
}

gmswsd

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: How to make a href in a cell?
« Reply #2 on: April 01, 2020, 09:54:23 am »
Thanks

Unfortunately, still could not get it to work.
If I remove the $.extend section it works.

<?php
   $my_data = array(
            [1, 'Exxon Mobil', 339938.0, 36130.0],
            [2, 'Wal-Mart Stores', 315654.0, 11231.0],
            [3, 'Royal Dutch Shell', 306731.0, 25311.0]
        );
   $my_data = json_encode($my_data);
?>

<!DOCTYPE html>
<html>
<head>
<!--jQuery dependencies-->
   <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css" />
   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
   <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>

<!--PQ Grid files-->
    <link rel="stylesheet" href="../lib/paramquery/pqgrid.min.css" />
    <link rel="stylesheet" href="../lib/paramquery/pqgrid.ui.min.css" />
    <!--office theme-->
    <link rel='stylesheet' href='../lib/paramquery/themes/office/pqgrid.css' />

    <script src="../lib/paramquery/pqgrid.min.js"></script>
    <!--for localization and intellisense -->
    <script src="../lib/paramquery/localize/pq-localize-en.js"></script>

<!--for touch devices-->
    <script src="../lib/paramquery/pqTouch/pqtouch.min.js"></script>

<!--jsZip for zip and xlsx import/export-->
    <script src="../lib/paramquery/jsZip-2.5.0/jszip.min.js"></script>

<style>
    *{
        font-size:12px;
        font-family: Arial;
    }
</style>
<script>
    $(function () {

        var data =  <?php echo $my_data ?>;
        var obj = {
            numberCell:{resizable:true,title:"#",width:30,minWidth:30},
            editor: {type: 'textbox'},
            title: "ParamQuery Grid with Array data",
            resizable:true,
            scrollModel:{autoFit:true, theme:true}
        };
        obj.colModel = [
            { title: "Rank", width: 100, dataType: "integer" },
            { title: "Company", width: 200, dataType: "string" },
            { title: "Revenues ($ millions)", width: 150, dataType: "float", format: '$#,###.00' },
            { title: "Profits ($ millions)", width: 150, dataType: "float", format: '$#,###.00'}
        ];
        $.extend(obj.colModel[1], {
            column.render = function( ui ){
                return "<a href='test.html'>" + ui.cellData + "</a>";
            }
        });
        obj.dataModel = { data: data };
        $("#grid_array").pqGrid(obj);
    });


</script>
</head>
<body>
<div id="grid_array" style="margin:100px;"></div>
</body>

</html>

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: How to make a href in a cell?
« Reply #3 on: April 01, 2020, 10:28:30 am »
Please correct the syntax:

Code: [Select]
$.extend(obj.colModel[1], {
            render: function( ui ){
                return "<a href='test.html'>" + ui.cellData + "</a>";
            }
        });

gmswsd

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: How to make a href in a cell?
« Reply #4 on: April 01, 2020, 06:40:59 pm »
Thank You.  That worked perfectly!