douwudie8060 2014-07-18 06:47
浏览 35

DataTables:下拉变化

First of all its not about filtering(searching) of drop-down.

I am using Datatables : where one of my column has drop-down , i want when i change or select any option from it ... its should pass to it resp value

$(document).ready(function () {
    dt = $('#example').DataTable({
        "pagingType": "full_numbers",
        "scrollY": "440px",
        "scrollX": "100%",
        "scrollCollapse": true,
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "/server_processing.php",
        "deferRender": true,
        "aoColumns": [{
                className: "center",
                "class": "details-control",
                "orderable": false,
                "data": null,
                "defaultContent": "",
            },
            { className: "center", },
            { className: "center", },
            { className: "center", },
            { className: "center", },
            { className: "center", },
            { className: "center", },

        ],
        "columnDefs": [{
           "aTargets": [7],
           "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
               $(nTd).css('text-align', 'center');
           },
           "mData": null,
           "mRender": function (data, type, full) {
              return '<td><select id="dynamic_select" name="dynamic_select">
\
                              <option id="0" value="">Select</option/>
\
                              <option id="1" value="test.php">1</option/>
\
                              <option id="2" value="test2.php">13</option/>
\
                              <option id="31" value="test3.php">12</option/>
\
                           </select></td>';

            }

        }]

    });

    $('select[name=dynamic_select]').on('change', function () {
        var attvalue = $(this).children(":selected").attr("id");

        var mainval = $(this).val();

        var url = mainval;

        if ($(this).children(":selected").attr("id") == 0) {

        } else if ($(this).children(":selected").attr("id") == 1) {
            window.open(url, "_self");
        } else {
            window.open(url, "_self");
        }

        return false;
    });

});

below is my HTML

 <table id="example" class="display" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th></th>
            <th>First name</th>
            <th>Last name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Start date</th>
            <th>Salary</th>
            <th></th>
        </tr>
    </thead>

    <tfoot>
        <tr>
            <th></th>
            <th>First name</th>
            <th>Last name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Start date</th>
            <th>Salary</th>
            <th></th>
        </tr>
    </tfoot>

</table>

All is working fine ... just on change of select value .. i need it should go to resp. Url with its resp. id

Also can i define each row a unique id ( or my database primary id ) ?

Note : if i put above jquery in my simple PHP then its working .. but don't know why its not working in data-tables

Please help me

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作