showing button on the if condition.

showing button on the if condition.

majkellvzmajkellvz Posts: 8Questions: 3Answers: 0
edited March 2019 in Free community support

I am on symfony 4 and I am trying to show a button depending on the status of a property if it is sold or not

{ "data": "issold",
                        "orderable":false,
                        render : function ( data, type, row ) {
                            if (data){
                                return '<a href="/property/sold/' + row.id + '" title="Sold"><i class="material-icons" style="font-size:25px">attach_money</i></a>';
                            } else {
                                return '<a href="/property/sold/' + row.id + '" title="UnSold"><i class="material-icons" style="font-size:25px">money_off</i></a>';
                            }
                        }}

EDIT: Updated to use Markdown formatting.

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,311Questions: 26Answers: 4,948
    edited March 2019 Answer ✓

    You will need to fix your if statement. Something like this:

    if (data === 'Sold'){
    

    Kevin

  • majkellvzmajkellvz Posts: 8Questions: 3Answers: 0

    it is a boolean type and still nothing
    if (data === true){

  • majkellvzmajkellvz Posts: 8Questions: 3Answers: 0

    @kthorngren I marked it answered by mistake

  • kthorngrenkthorngren Posts: 21,311Questions: 26Answers: 4,948

    I don't see anything that stands out as an issue. We would need to see your data to help. Without actually seeing the problem we would just be guessing. Can you put together a simple test case?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    You could use a console log statement to see what the data is, for example:

                            render : function ( data, type, row ) {
                                console.log(data);
                                if (data){
    

    Kevin

  • kthorngrenkthorngren Posts: 21,311Questions: 26Answers: 4,948

    I marked it answered by mistake

    @allan or @colin should be able to change it.

    Kevin

  • majkellvzmajkellvz Posts: 8Questions: 3Answers: 0

    console log is empty

    Michael

  • kthorngrenkthorngren Posts: 21,311Questions: 26Answers: 4,948
    edited March 2019 Answer ✓

    I would suggest looking at the returned data using the browser's dev tools. Look at the network response. Is the issold object populated there?

    Kevin

  • majkellvzmajkellvz Posts: 8Questions: 3Answers: 0

    Yea I found the error. Many thanks!

This discussion has been closed.