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!
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!
Share Improve this question edited Apr 10, 2015 at 9:28 Ambareesh Surendran 5082 silver badges12 bronze badges asked Apr 10, 2015 at 9:24 WaelhiWaelhi 3152 gold badges8 silver badges19 bronze badges 03 Answers
Reset to default 2If 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+'"/>';
}
}
]
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:
- value: the field value.
- row: the row record data.
- index: the row index.
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
}
}]
});
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" />';
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745262534a4619276.html
评论列表(0条)