Foreign key fields on accessing return 'Undefined'

Issue #83 resolved
Ashish Kaul created an issue

Im having [this](https://stackoverflow.com/questions/69586490/cannot-access-the-foreignkey-data-in-datatables) which I have posted on stackoverflow where when I try to access the field of a foriegn key field, it results as Undefined. When I try to console.log the data on using

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

It gives me the str value of that table and not the particular object. Observe the 6th array index which is a string and not the object.

Array(10) [ "2021-10-16 06:25:36+00:00", "Vibula", "email@gmail.com", "9677******", "EMAESTER", "He/She is IT by profession || Looking for online teaching Job", "randomemail@gmail.com", "False", "Not Dialed", "" ]

0: "2021-10-16 06:25:36+00:00"

1: "Vibula"

2: "email@gmail.com"

3: "9677******"

4: "EMAESTER"

5: "He/She is IT by profession || Looking for online teaching Job"

6: "randomemail@gmail.com"

7: "False"

8: "Not Dialed"

9: ""

length: 10

<prototype>: Array []
 randomemail@gmail.com

How do I fix this?

Comments (2)

  1. Ashish Kaul reporter

    Completely missed that there is a method called render_function which does exactly what render option does in jquery.
    This is what I did:

    def render_column(self, row, column):
            # We want to render teacher as a custom column
            if column == 'teacher':
                print row.teacher.first_name, row.teacher.email
                # escape HTML for security reasons
                return '{0}<br>({1})'.format(row.teacher.first_name, row.teacher.email)
            else:
                return super(ReferralsJSON, self).render_column(row, column)
    

  2. Log in to comment