Bootstrap-table: ajax within Detail Formatter function

Created on 2 Jun 2015  路  5Comments  路  Source: wenzhixin/bootstrap-table

Instead of loading all the data for each detail view I'd like to pull it using ajax only when the row is shown. However, the following function does not show the data

function detailFormatter(index, row) {
    $.get('/ajax/details.php', { id:row.parentID }, function(data) {
        return data;
    });
}
help-wanted

Most helpful comment

You can look at our example: http://issues.wenzhixin.net.cn/bootstrap-table/

Source: https://github.com/wenzhixin/bootstrap-table-examples/blob/master/welcome.html

For example:

$table.on('expand-row.bs.table', function (e, index, row, $detail) {
    $detail.html('Loading from ajax request...');
    $.get('LICENSE', function (res) {
        $detail.html(res.replace(/\n/g, '<br>'));
    });
});

All 5 comments

Provide a fiddle please

You can look at our example: http://issues.wenzhixin.net.cn/bootstrap-table/

Source: https://github.com/wenzhixin/bootstrap-table-examples/blob/master/welcome.html

For example:

$table.on('expand-row.bs.table', function (e, index, row, $detail) {
    $detail.html('Loading from ajax request...');
    $.get('LICENSE', function (res) {
        $detail.html(res.replace(/\n/g, '<br>'));
    });
});

I found a solution. But involve modify the bootstrap master table.js , in the section where construct the tr > and td colspan="XX" where detail data will appear. I added an ID attribute using the same table index in the line: " $tr.after(sprintf(' < tr class="detail-view" > < td colspan="%s" id="' + index + '">%s< /td >< /tr >', "

Then this is my javascript function:
image

The problems seems all the data obtained (res) inside $.get function only exists inside, you can pass to outer function , i tried return, assign to other var to use it in the detailformatter (external function) but nothing seems to work. I'm very rookie with javascript code. But works very well with the changes i described. And the last two lines are necessary to create the blank row. I hope this was useful for others. This is the best bootstrap table framework i found. Good job!!!

Well,
I have the same problem loading data into the detailFormatter.
the documentation does not explain how to call an external file inside the details part.
Is there any way to load a template part in WordPress to there? any PHP file?

tried:
data-detail-formatter="<?php get_template_part('template-parts/content', 'filename'); ?>"

ehm you mean this?

you need "$detail" after "row" in the dateilFormatter

function detailFormatter(index, row, $detail) { $.ajax({ url: "/planung/subdata.php", method: 'GET', dataType: 'html' }).done(function(data){ $detail.html(data) }) }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BallaLakshmi picture BallaLakshmi  路  3Comments

alejandrofm picture alejandrofm  路  4Comments

e1xsd picture e1xsd  路  4Comments

rajeshbtlit picture rajeshbtlit  路  4Comments

marceloverdijk picture marceloverdijk  路  3Comments