如果状态为“2”,然后为“现金”,则需要根据条件为payment_type添加标签,并为“1”提供信用。
这是我的javascript代码:
/*
* Editor client script for DB table odenis
* Created by http://editor.datatables.net/generator
*/
(function($){
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: 'php/table.odenis.php',
table: '#odenis',
fields: [
{
"label": "Öd\u0259ni\u015f üsulu:",
"name": "usul",
"type": "radio",
"options": [
{ label: "Nəğd", value: "1" },
{ label: "Kontur", value: "2" }
//"1" ,
//"2"
]
},
{
"label": "Öd\u0259ni\u015f müdd\u0259ti:",
"name": "muddet",
"type": "radio",
"options": [
{ label: "Aylıq", value: "1" },
{ label: "Yığılsın deyərəm", value: "2" },
{ label: "10 günlük", value: "3" },
{ label: "Həftəlik", value: "4" },
{ label: "15 günlük", value: "5" }
]
},
{
"label": "Öd\u0259ni\u015f tarixi:",
"name": "tarix",
"type": "datetime",
"format": "YYYY-MM-DD"
},
{
"label": "Öd\u0259ni\u015f miqdar\u0131:",
"name": "miqdar"
}
]
} );
var table = $('#odenis').DataTable( {
dom: 'Bfrtip',
ajax: 'php/table.odenis.php',
columns: [
{
"data": "usul",
},
{
"data": "muddet"
},
{
"data": "tarix"
},
{
"data": "miqdar"
}
],
select: true,
lengthChange: false,
buttons: [
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
} );
} );
}(jQuery));
这是php:
<?php
$cariid = file_get_contents('../../cariid.txt');
/*
* Editor server script for DB table odenis
* Created by http://editor.datatables.net/generator
*/
// DataTables PHP library and database connection
include( "lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
// The following statement can be removed after the first run (i.e. the database
// table has been created). It is a good idea to do this to help improve
// performance.
$db->sql( "CREATE TABLE IF NOT EXISTS `odenis` (
`id` int(10) NOT NULL auto_increment,
`obyekt_id` varchar(255),
`usul` varchar(255),
`muddet` varchar(255),
`tarix` date,
`miqdar` varchar(255),
PRIMARY KEY( `id` )
);" );
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'odenis', 'id' )
->fields(
Field::inst( 'obyekt_id' )
->set( false ),
Field::inst( 'usul' )
->validator( 'Validate::notEmpty' ),
Field::inst( 'muddet' )
->validator( 'Validate::notEmpty' ),
Field::inst( 'tarix' )
->validator( 'Validate::notEmpty' )
->validator( 'Validate::dateFormat', array( 'format'=>'Y-m-d' ) )
->getFormatter( 'Format::date_sql_to_format', 'Y-m-d' )
->setFormatter( 'Format::date_format_to_sql', 'Y-m-d' ),
Field::inst( 'miqdar' )
->validator( 'Validate::notEmpty' )
)
->where( 'obyekt_id', $cariid )
->process( $_POST )
->json();
在编辑按钮(图2)中正常工作。但我也需要在表格中。 enter image description here
答案 0 :(得分:0)
使用渲染解决了。
data:"usul",
render:function ( data, type, row ) {
var melumat = data;
if((type === "display" || type === "filter") && melumat ==1){
return 'Nəğd';
}
else if((type === "display" || type === "filter") && melumat ==2){
return 'Kontur';
}
else{
return data;
}
}