【问题标题】:Need to change the label based on the row value in run time需要根据运行时的行值更改标签
【发布时间】:2017-03-23 22:40:04
【问题描述】:

需要根据条件为payment_type添加标签,如果状态为“2”然后是“现金”和“1” - 信用。

photo

这是我的 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

【问题讨论】:

  • 你如何生成这个表?显示您的代码。
  • 我分享了代码和截图。我该如何解决?

标签: javascript php jquery ajax datatables


【解决方案1】:

通过渲染解决。

                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;
                    }

                }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-22
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多