yii2 jquery ajax,Yii2 + jQuery DataTable + Ajax

I am new to Yii and need some help.

I am using Yii2.

I have a page where I use DataTable trying to populate it with ajax from the database.

The data returned from the controller does not display in the table.

I installed the DataTable extension.

I installed yadcf

My html:

Customer

My ajax controller has this function:

public function actionGetinvoices() {

$company_id = isset($this->dataBody['company_id'])?$this->dataBody['company_id']:null;

if ($company_id === null)

$this->sendResponse(501,array('error'=>'Invalid company found'));

$output = array();

$output['aaData'] = '';

$invoices = InvoiceDiscountReport::getInvoices($company_id);

$aColumns = array('invoice_discount_report__debtor__name');

if(!empty($invoices))

{

foreach($invoices as $inv)

{

$row = array();

for($i=0; $i

{

$row[] = $inv[$aColumns[$i]];

}

$output['aaData'][] = $row;

}

}

$this->sendResponse(200,$output);

}

My js file has this code:

var myTable = $('#invoicesTbl').DataTable({

retrieve: true,

paging: false,

"language": {

"emptyTable": "There are no invoices for the company",

"bProcessing": true,

"bDestroy": true,

"sAjaxSource": '/api/dashboard/getinvoices&company_id=49',

"bAutoWidth": true,

"aaSorting": [[ 0, "asc" ]],

"aoColumns": [

{ "bSortable": true, "sWidth": "100%" },

],

}

});

yadcf.init(myTable, [

{column_number : 0, filter_type: "text", text_data_delimiter: ","}

],'footer');

});

The data returned from my controller looks like this:

{"aaData":[["SIGAL ZAHAVI"]]}

What I get is an empty table with: There are no invoices for the company.

Can someone please help me and tell what am I doing wrong?

Thank you

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值