JSON array as table, ignoring columns and injecting object for each cell

JSON array as table, ignoring columns and injecting object for each cell

biggiesmallsbiggiesmalls Posts: 1Questions: 0Answers: 0

Hi guys,

Ive got an array of data that i want to use like so :

[{'tradable': 1, 'link': '', 'icon_url': 'http://steamcommunity-a.akamaihd.net/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXU5A1PIYQNqhpOSV-fRPasw8rsQEl9Jg9SpIW1KgRrg6KGIWgS6Izhl4Xfw6XwMOiDwG0Cu8dziLiR9Ijw3lCy8kdtYmr1doKSexh-Pw9cMjR1vQ/95fx95f', 'marketable': 1, 'market_name': u'Sticker Capsule', 'desc_id': '384801280_0', 'id': '126979456', 'pos': 88}, {'tradable': 1, 'link': 'steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D4793699345104825810', 'icon_url': 'http://steamcommunity-a.akamaihd.net/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpopbmkOVUw7ODHTi5W4867kpKEmePLPr7Vn35cpsdwi-_Hoo-g2wOx-0NoYW31LITAdAU9YA3Z-lnvkO_vjcLptcybwXV9-n51LW6fRVs/95fx95f', 'marketable': 1, 'market_name': u'SCAR-20 | Storm (Field-Tested)', 'desc_id': '519981712_519977179', 'id': '555454682', 'pos': 67}]

Ive got this being injected into a hidden div via my django template and then im using parseJSON js call to bring it into a object. What im not understanding is how to display my array cell by cell ignoring any column requirements and looping through my key/value pairs to display an image (based on the icon_url) and text underneath that (in the same cell).

I don't require columns to be static (x data in y column), i just want to be able to paginate/search my table with datatables.

Ive tried settling all the columns to null value and then looping through to display my array, it can see the array (showing 1 of 91..) but when i try to add a object['key'] to a column it spits back a parameter error.

Am i actually going about this the correct way? I dont really need this to be ajax called because the load time to the client is not important as well as the page refresh. The other way i tried was to use a django template forloop build the table like so:

<table id="table" class="compact" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
            </tr>
        </thead>
        <tbody>
        {% for x in inventory|dictsort:"pos" %}
            {% if x.marketable == 1 %}
                {% cycle '<tr>' '' '' '' '' %}
                <td>    
                    <center>
                        <img src="{{ x.icon_url }}">
                            <br>
                                {{ x.market_name }}
                    </center>
                </td>
                {% cycle '' '' '' '' '</tr>' %}
            {% endif %}
        {% endfor %}
        </tbody>
</table>

This was giving me parameter errors based on the last item in the array, i can see the error in my way, ie, the last item should end with a </tr> but that means the column (5 across) would end prematurely..

Thanks in advance for any help.

Regards,

This discussion has been closed.