Search code examples
jquery-bootgrid

Not able to print the child table values in bootstarap bootgrid


JSON response:

{
    "current": 1,
    "rowCount": 10,
    "rows": [
        {
            "id": 19,
            "sender": "[email protected]",
            "received":"[
        {
            "name":"received1"
        }
    ]
        }
    ]
},
{
    "id": 14,
    "sender": "[email protected]",
    "received":  [
        {
            "name":"received2"
        }
    ]
},
    ...],
"total": 1123}

I want to print the received name using bootgrid.

Example:

<th data-column-id="id" data-identifier="true">Id</th>
<th data-column-id="received.name">Name</th>

I am able to print received.name, but not able to print id.


Solution

  • For the above issue we have to use data-formatter in bootstrap bootgrid.

    i have attached the code here, hope it will helpful.

    <script>  $("#MyTable").bootgrid({
                ajax: true,formatters: {
                    "link": function (column, row) 
                    {
                        return "<span>" + row.received.name+ "</span>";
                    }
                }}); 
    </script>
    

    Your Html will like

     <table>
     <th data-column-id="received.name" data-formatter="link">Anything</th> 
     </table>