fnCreatedCell

fnCreatedCell

t3mh4t3mh4 Posts: 3Questions: 0Answers: 0

i am using fnCreatedCell like below;

{
"targets": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
var td = $(nTd);/Convert js to jq/
var amount = $(nTd).data("amount");
td.append("<i class='fa fa-thumbs-o-down'></i>");
if(amount=="0")
{
td.append("<i class='fa fa-thumbs-o-down'></i>");
}
else {
td.append("<i class='fa fa-thumbs-o-up'></i>");
var expl = td.data("expl");
if(expl!="")
{
td.append("*");
td.click(function () {
toastr"info";
});
}
}
}
}

i added each cell an icon.when table created,row is collapsed.then i expand it and my icons dont show in table.

Replies

  • allanallan Posts: 63,831Questions: 1Answers: 10,518 Site admin

    You should use columns.render to output HTML rather than columns.createdCell. The latter should only be used to add data / events to the cell.

    Allan

  • t3mh4t3mh4 Posts: 3Questions: 0Answers: 0

    Ok but as you see in my code i need to access td.i could not find any way to access td in columns.render

  • allanallan Posts: 63,831Questions: 1Answers: 10,518 Site admin

    As you say, there isn't an easy way of doing that. Can you give me a link to the page so I can take a look please? Is the data DOM sourced or Ajax sourced?

    Allan

  • t3mh4t3mh4 Posts: 3Questions: 0Answers: 0
    edited December 2016

    sorry bu i did not publish my web page yet.i designed it with mvc.Here is my table

    <table id="dtTable" class="table table-condensed table-bordered display responsive nowrap" style="width:100%;text-align:center" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Kişi</th>
                            <th>Ocak</th>
                            <th>Şubat</th>
                            <th>Mart</th>
                            <th>Nisan</th>
                            <th>Mayıs</th>
                            <th>Haziran</th>
                            <th>Temmuz</th>
                            <th>Ağustos</th>
                            <th>Eylül</th>
                            <th>Ekim</th>
                            <th>Kasım</th>
                            <th>Aralık</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (dynamic item in ViewBag.Dues.Keys)
                        {
                            <tr>
                                <td style="text-align:left">
                                    @{ /*Kişi Ad Soyad*/}
                                @item
                            </td>
                            @foreach (var month in ViewBag.Dues[item])
                            {
                                <td style="vertical-align:middle;" data-amount='@month.Amount' data-expl='@month.Expl'></td>
                            }
                        </tr>
                       }
                    </tbody>
                </table>
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,831Questions: 1Answers: 10,518 Site admin

    Okay - it is DOM sourced then. In which case, why use DataTables to render the icons at all? Can you not just do that in your server-side code?

    Allan

This discussion has been closed.