HTML table as data source and "data": null column

HTML table as data source and "data": null column

sergedasergeda Posts: 42Questions: 16Answers: 0

I need to show different icons for some rows. I set it in php and set this column as "data": null to not process it by Editor. But now it doesn't show up my content. I've tried to use columns.render but in this function I also doesn't have access to data in column. How can I achieve what I need?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,821Questions: 1Answers: 10,126 Site admin

    I'm afraid I will need a little more information - I don't really understand what you are looking for at the moment. If you want to show icons, then columns.render probably is the best way to do it. The third parameter passed into the function is the data object for the whole row, while the first parameter is controlled by columns.data (if you set it to null, then null is passed in as the first parameter).

    It would be helpful if you should link tot he page that you are having issues with or show some code.

    Allan

  • sergedasergeda Posts: 42Questions: 16Answers: 0

    In php I have code to form a table like this:

            <?php foreach ($corporations as $corporation):?>
                <tr id="<?=$corporation->id?>">
                    <td class="phone"><?=$corporation->phone?></td>
                    <td class="email"><?=$corporation->email?></td>
                    <td class="action"><?=($canEdit)?'<span  class="action"><span class="glyphicon glyphicon-edit edt"></span><span class="glyphicon glyphicon-remove del"></span></span>':'' ?></td>
                </tr>
            <?php endforeach?>
    

    So if user have permissions to edit row I show him icons, if not - I don't show.
    In JS for this column I have

               {
                    "data": null,
                    "render": function ( data, type, row ) {
                        return data +' ('+ row[3]+')';
                    }
                }
    

    I want in this render function somehow get content of my action cell but there is no this cell in data and row objects.

  • allanallan Posts: 61,821Questions: 1Answers: 10,126 Site admin

    Doesn't your PHP template already do this? I don't see why you would need to render anything using Javascript.

    Allan

  • sergedasergeda Posts: 42Questions: 16Answers: 0
    edited March 2015

    The problem is: it renders fine only if I remove "data": null for this column.
    With this:

      {
                    "data": null
       }
    

    all action cells doesn't have an icon and have [object Object]

  • allanallan Posts: 61,821Questions: 1Answers: 10,126 Site admin

    Can you link to the page so I can debug it please?

    Allan

  • sergedasergeda Posts: 42Questions: 16Answers: 0
    edited March 2015

    Sorry, it is on my local computer now.
    I've managed to render icons with this:

                {
                    "data": null,
                    "render": function ( data, type, full, meta ) {
                        var tr=meta.settings.aoData[meta.row].nTr;
                        return $(tr).find('td.action').html();
                    }
                }
    

    But with this I have another problem:
    When I edit row in editor it returns row without this icons again :(
    How can I render row the same way on editor save?

  • allanallan Posts: 61,821Questions: 1Answers: 10,126 Site admin

    Can you render the icons using return '<img .../>'; rather than reading from HTML that might or might not exist at that point (the nTr property is not always available there).

    Allan

  • sergedasergeda Posts: 42Questions: 16Answers: 0

    I don't have needed data in javascript to decide if icon should be placed or not. And make request to server on each row is not a good solution

  • allanallan Posts: 61,821Questions: 1Answers: 10,126 Site admin

    You have access to the full data for the row and you could also add additional information to it that isn't displayed int he table if that isn't enough.

    Allan

  • sergedasergeda Posts: 42Questions: 16Answers: 0

    Can you give a bit more information. Some sample code? Can't get what you propose to do

  • allanallan Posts: 61,821Questions: 1Answers: 10,126 Site admin
    Answer ✓

    It is hard to do so without being able to see the page since I don't know what data you have available, but here is a trivial modification of the code above:

    {
        "data": null,
        "render": function ( data, type, full, meta ) {
            return full.showIcon ?
               '<img src="/icons/edit.png" /> :
               '';
        }
    }
    

    Allan

This discussion has been closed.