我在JQXgrid中创建了按钮渲染器,当按下按钮时,它将数据传递给控制器,控制器发送到模型,然后返回来自mysql数据的结果。
这是我的视图代码部分按钮渲染器:
ListChange
这是我的视图代码 - 将数据传递给控制器:
var button_renderer = function (row, columnfield, value, defaulthtml, columnproperties) {
var kode_keramik = $('#jqxgrid').jqxGrid('getcelltext', row, "kode_keramik");
button = '<a href="#modal_details" class="btn btn-xs btn-success view_details" id="'+ kode_keramik +'" >Proceed</a>';
return button;
};
这是我的控制者:
$(document).on('click', ".view_details", function() {
//alert("aaa");
var url = "<?php echo base_url().'getGlazeMM/ajax_get_item_list'?>";
kode_keramik = this.id;
$.post(url, {kode_keramik: kode_keramik} ,function(data) {
$('.modal-body').empty();
$('.modal-body').append(data);
$('#modal_details').modal();
});
});
最大的问题是如何从public function ajax_get_item_list(){
$data['post'] = $_POST;
$kode_keramik = $_POST['kode_keramik'];
//$buyer = $_POST['buyer'];
$this->load->model('get_glaze');
$data['item_list'] = $this->get_glaze->action_ajax_get_item_list( $data['post'] );
if ($data['item_list']){
echo "<table class='table table-bordered'>
<tr>
<th>Inspect Date</th>
<th>Item Code</th>
<th>Type</th>
<th>Hasil KW1</th>
<th>Total Inspek</th>
<th>Aktual Yield</th>
<th>Buyer</th>
</tr>";
foreach ($data['item_list'] as $key => $value) {
echo "<tr>";
echo "<td>".$value['inspect_date']."</td>";
echo "<td>".$value['item_code']."</td>";
echo "<td>".$value['sell_type']."</td>";
echo "<td>".$value['hasil_kw1']."</td>";
echo "<td>".$value['total_inspek']."</td>";
echo "<td>".$value['aktual_yield']." %</td>";
echo "<td>".$kode_keramik."</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "Data tidak ditemukan";
}
}
+ 第二个值 传递多个数据
view_details" id="'+ kode_keramik +'"
进入:
var button_renderer = function (row, columnfield, value, defaulthtml, columnproperties) {
var kode_keramik = $('#jqxgrid').jqxGrid('getcelltext', row, "kode_keramik");
button = '<a href="#modal_details" class="btn btn-xs btn-success view_details" id="'+ kode_keramik +'" >Proceed</a>';
return button;
};
直到控制器:
var url = "<?php echo base_url().'getGlazeMM/ajax_get_item_list'?>";
kode_keramik = this.id;
***SECOND VALUE;***
$.post(url, {kode_keramik: kode_keramik, ***SECOND VALUE***} ,function(data) {
答案 0 :(得分:0)
您可以将数据格式化为一个JSON
对象,并将其放在自定义html属性中。
示例强>
请注意单引号和 双引号转义 。
var button_renderer = function (row, columnfield, value, defaulthtml, columnproperties) {
var kode_keramik = $('#jqxgrid').jqxGrid('getcelltext', row, "kode_keramik");
button = "<a href='#modal_details' class='btn btn-xs btn-success view_details' data-custom='{\"kode_keramik\": \"" + kode_keramik + "\", \"second\": \"value\"}'>Proceed</a>";
return button;
};
使用jQuery
$(document).on('click', ".view_details", function() {
//alert("aaa");
var url = "<?php echo base_url().'getGlazeMM/ajax_get_item_list'?>";
var obj = $(this).data('custom'); // get object using jQuery
$.post(url, obj ,function(data) {
$('.modal-body').empty();
$('.modal-body').append(data);
$('#modal_details').modal();
});
});
它将自动解析对象。