Reputation: 315
I'm having a problem in bootstrap table, I have a bootstrap table populated by a data from a database by using JQuery AJAX
, what I want to do is insert/add <input type="text"/>
on last column on every record.
My Jquery Script:
<script type="text/javascript">
$(function(){
var baseurl = "<?php print site_url('/quotes/get'); ?>";
$.ajax({
method: "POST",
url: baseurl,
data: { analid: 1 },
dataType: 'json'
})
.done(function( msg ) {
console.log(msg);
$('#qtable').bootstrapTable({
data: msg
});
});
});
</script>
the script above is working displaying the data from database, then I found this reference(LINK HERE), on the bottom part of that web is where I saw some method of bootstraptable
like adding static column.
Updated Code Jquery Script:
$(function() {
var baseurl = "<?php print site_url('index.php/quotes/get'); ?>";
$.ajax({
method: "POST",
url: baseurl,
data: {
analid: 1
},
dataType: 'json'
})
.done(function(msg) {
console.log(msg);
$('#qtable').bootstrapTable({
data: msg,
columns: [{ //<--- here is where I lost.. I don't know what to do here or what should I add..
field: 'operate',
title: 'Item Operate',
align: 'center',
valign: 'middle',
clickToSelect: false,
formatter: operateFormatter,
events: operateEvents
}]
});
});
});
Any alternative and optimized way solutions is much appreciated.
Thanks!
Upvotes: 0
Views: 7146
Reputation: 2622
If you want to return / render column at known position, simply use the following function block
formatter : function(value,row,index) {
return '<input name="elementname" value="'+value+'"/>';
}
If you want to exclude / skip some columns or want to render particular column (add empty curly braces pairs {},{},{}, like this according to how much column you have to shift) for example,
columns: [ {},{},{},
{
field: 'operate',
title: 'Item Operate',
align: 'center',
valign: 'middle',
clickToSelect: false,
formatter : function(value,row,index) {
return '<input name="elementname" value="'+value+'"/>';
}
}
]
Upvotes: 2
Reputation: 6031
you can use column option formatter
. see example HERE
formatter : function(value,row,index) {
return '<input name="elementname" value="'+value+'"/>';
//return '<input name="elementname" value="'+row.id+'"/>'; here id is your field name
}
The cell formatter function, take three parameters:
in this case your code will be as below.(assume that 'operate' is your last column name )
$('#qtable').bootstrapTable({
data: msg,
columns: [{ //<--- here is where I lost.. I don't know what to do here or what should I add..
field: 'operate',
title: 'Item Operate',
align: 'center',
valign: 'middle',
clickToSelect: false,
formatter : function(value,row,index) {
return '<input name="elementname" value="'+value+'"/>';
//return '<input name="elementname" value="'+row.id+'"/>'; here id is your field name
}
}]
});
Upvotes: 1
Reputation: 1462
I am not familiar with this library, but I looked at the docs and this is what I think you need. formatter can just be a anonymous function like this:
formatter : function(value) {
//value contains the current value in the cell. whatever you return will be the new value of the cell.
return '<input name="myinput" />';
}
Upvotes: 1