Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript cakephp中的jQuery数据表可点击行_Javascript_Jquery_Cakephp - Fatal编程技术网

Javascript cakephp中的jQuery数据表可点击行

Javascript cakephp中的jQuery数据表可点击行,javascript,jquery,cakephp,Javascript,Jquery,Cakephp,我在自定义cakePHP脚本中使用jQuery Datatables-由于我的表中的信息非常长,我希望通过删除最后一列(查看/编辑)来减少我的表,并使整行可单击 以下是我当前的代码: <table class="responsive_table" id="quotes_table"> <thead> <tr> <th>Date</th>

我在自定义cakePHP脚本中使用jQuery Datatables-由于我的表中的信息非常长,我希望通过删除最后一列(查看/编辑)来减少我的表,并使整行可单击

以下是我当前的代码:

    <table class="responsive_table" id="quotes_table">
        <thead>
            <tr>
                <th>Date</th>
                <th>Client</th>
                <th>Project</th>
                <th class="center">Total</th>
                <th class="center">Status</th>
                <th class="center no_sort">View/Edit</th>
            </tr>
        </thead>
        <?php foreach($quotes as $quote) : ?>
            <tr>
                <td><?php echo $quote['Quote']['quote_date']?></td>
                <td ><?php echo $quote['Client']['client_name']?></td>
                <td><?php echo $quote['Quote']['project']?></td>
                <td class="right"><?php echo $currency. number_format($quote['Quote']['quote_total'], 2, '.', ',')?></td>
                <td class="quote_status"><?php echo $quote['Quote']['status']?></td>
                <td class="center small_cell">
                <?php echo $this->Html->link('View/Edit', array('action' => 'view', $quote['Quote']['id'], '?' => array('nocache' => time())), array('class' => 'view')); ?>
                </td>
            </tr>
        <?php endforeach; ?>
    </table>

    <?php echo $this->Html->script('jquery.dataTables');?>
    <script type="text/javascript">
        if ( $('#quotes_table')[0] ) { 
            $('#quotes_table').dataTable( {
            "aaSorting": [[ 0, "desc" ]],
            "sDom": '<"top"f>irt<"bottom"lp><"clear">',
            "oLanguage": {
             "sSearch": "Search (Auto Filter):"},
             "fnDrawCallback": function( oSettings ) { updateClasses(); }
            } 
        ); }
    </script>

日期
客户
项目
全部的
地位
查看/编辑
如果($('#quotes_table')[0]){
$('quotes_table')。数据表({
“aaSorting”:[[0,“desc”]],
“sDom”:“irt”,
“语言”:{
“搜索”:“搜索(自动筛选):”},
“fnDrawCallback”:函数(oSettings){updateClasses();}
} 
); }
还请注意,我的编辑链接包含某种数组。最好的方法是什么?

由于cakephp
link()
方法很难穿透,您可以将其保留在原位,并在客户端处理表行-隐藏“查看/编辑”单元格,并在单击其表行时触发其href

首先,为了简化jQuery选择,请将表行包装为


我们需要知道
$this->Html->link(…)
是如何工作的。它有文档记录吗?@Roamer-1888它是一个cakephp
HTML
helper函数,可以更好地创建
链接(锚定标记),服务的HTML是什么样子的?编辑按钮的服务HTML基本上是myurl.com/quotes/view/80?nocache=1436350852-80在这种情况下是引号,后面是nocache部分,它只是添加了一个php时间戳非常感谢-这似乎用view/edit链接隐藏了列,但它不起作用当我点击一行时。此外,我似乎在单击行时遇到了一个错误:uncaughtrangeerror:最大调用堆栈大小超过了dmmm,我没有想到这一点-触发的单击必须传播回tr。试试
$a.triggerHandler('click')
</thead>
<tbody>
<?php foreach($quotes as $quote) : ?>
    ...
<?php endforeach; ?>
</tbody>
$('#quotes_table').dataTable({
    "aaSorting": [[ 0, "desc" ]],
    "sDom": '<"top"f>irt<"bottom"lp><"clear">',
    "oLanguage": {
        "sSearch": "Search (Auto Filter):"
    },
    "fnDrawCallback": function( oSettings ) { updateClasses(); }
}).find("tbody tr").each(function() {
    var $a = $(this).find("a.view"); //find view/edit anchor 
    $a.closest("td").hide(); //hide view/edit cell
    $(this).on('click', function() { //on clicking the table row, trigger a click on the anchor. 
        $a.trigger('click');
    });
});