【问题标题】:Issue the checkBox and select the action not done发出复选框并选择未完成的操作
【发布时间】:2015-05-05 14:06:12
【问题描述】:

当我在 select 和 coched all 复选框上选择操作并单击 ok 时遇到问题,请不要执行任何操作此数据表包含我以下代码的复选框:

function toggleChecks(obj) {
    $('.case').prop('checked', obj.checked);
}
$(document).ready(function () {
    tablecontact = $('#table-contact').dataTable({
        "info": true,
        "aoColumns": [{
            "sTitle": "<input type='checkbox' name='selectedContact[]' id='selectAll'  onclick='toggleChecks(this);' ></input>",
            "mDataProp": null,
            "sWidth": "20px",
            "sDefaultContent": "<input type='checkbox' id="
            table - selected - <?= $this - > idContact; ?> " value='<?=$this->idContact ;?>' class='case'></input>", "bSortable": false
        },
        null, null, null, null, null, null, null, null],
            'sDom': 'lTfr<"clearfix">tip',
            'oTableTools': {
            'aButtons': []
        },
            "fnRowCallback": function (nRow, aData, iDisplayIndex) { //lien edition
            $('td:eq(8)', nRow).html('<a href="/<?=Zend_Registry::get('
            Zend_Locale ')->getLanguage();?>/admin/contact-management/updatecontact/idContact/' + aData[0] + '"><b>' + aData[8] + '</b></a>');
            return nRow;
        },
    });

    var tt = new $.fn.dataTable.TableTools(table);
    $(tt.fnContainer()).insertBefore('div.dataTables_wrapper');

当我选择所有复选框时选择操作我想要执行操作并单击确定但不起作用

<select name="table-action" id="table-action" class="small">
    <option value="0">Appliquer à la sélection</option>
    <option value="unsetemailnotification">UnsetEmailNotification</option>
</select>
<button type="submit" class="small" id="actionContact">Ok</button>

在我的控制器上输入以下代码:

public function setemailnotificationAction()
    {
        $ids = explode(';', $this->_request->getParam('listId',0));
        $contact = new Admin_Model_DbTable_Contact();
        if(!empty($ids))
        {
            foreach($ids as $id)
            {
                if(!$contact->setemailnotificationContact(intval($id)))
                {
                    echo json_encode(array(
                            "response" => "false",
                            "errorMessage" => "Il y a eu une erreur dans l'activation de l'email notification: ". $id
                    ));
                    exit();
                }
            }

            ));
            exit();
        }

        exit();
    }

我在 .phtml 上这样做:

$('#actionContact').click(function(){

var confirmAction = true;
var listId = '';   
var selectAction = $("#table-action").val();
$(".sorting_1").find(':checkbox:checked').each(function(){
    if(listId.length == 0){
        listId +=  $(this).val();
    }else{
        listId += ";" + $(this).val();
    }           
});

});

【问题讨论】:

  • 请提供更多详细信息。你得到什么错误?您使用的是什么版本的 JQuery?
  • var tt = new $.fn.dataTable.TableTools(table); 中,变量table 没有在我能看到的任何地方定义。
  • 当我选择方法并单击 ok 时没有发生任何事情,我需要运行所选功能
  • 你解决了我提到的问题吗?你还做了什么,错误,什么? “什么都没有发生”不是描述性的。

标签: php jquery zend-framework checkbox jquery-datatables


【解决方案1】:

花了我一点时间,但我认为这就是你想要做的:

https://jsfiddle.net/Twisty/zfg3r4j6/

function toggleChecks(obj) {
    //$('.case').prop('checked', obj.checked);
    $.each($(".case"), function(){
        if($(this).is(":checked")){
            $(this).prop("checked", "");
        } else {
            $(this).prop("checked", "checked");
        }
    });
}

还会从 onclick='toggleChecks(this);' 切换到 JQuery 解决方案:

$("#selectAll").on("change", function () {
    toggleChecks($(this));
});

不确定你想用&lt;select&gt; 做什么,所以添加更多信息,我们可以提供帮助。

编辑:

我怀疑你正在遵循这个例子:https://editor.datatables.net/examples/api/checkbox.html ?

【讨论】:

  • 可以简化为 $(this).prop("checked", !$(this).is(":checked"));
  • 当我点击确定时,什么也没发生,我需要帮助
  • 当您单击确定按钮时,不清楚您的函数在做什么。请提供更多详细信息。它会做什么,你期望什么,你会得到什么错误?不能只是说它不起作用,那是没有帮助的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-06
  • 2020-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多