how can I view the data get from database to my gridview using php?

Alimin

I've been stuck with the same problem for 2 days. now I'm working how to display a value from database which is many to many relation.

the case now I need to search bill no from bill table in database which i have done it but i'm stuck with displaying the value which the value of bill no from bill table, collection name from collection table, organization name from organization table relate account id in account table relate to bill table in account id, and need to display customer name full name(first+last).

this my billsController

public function actionLoadRequest($order_number)
    {
        if (!Yii::$app->request->isAjax) {
            return $this->asJson([
                "status" => false,
                "message" => "Unknown request method.",
                "data" => []
            ]);
        }

        $data = Bill::find()->where(['bill_no'=>$order_number])->one();


        return $this->asJson([
            "status" => true,
            "message" => "",
            "data" => $data
        ]);
    }

this is my view

<template v-if="isLoading">
                                                <tr>
                                                    <td colspan="7" class="center aligned">Processing...</td>
                                                </tr>
                                            </template>
                                            <template v-else>
                                                <template v-if="data.length > 0">
                                                    <tr v-for="$bill in data">
                                                        <td>{{bill.bill_no}}</td>
                                                        <td>{{bill.collection}}</td>
                                                        <td>{{bill.organization}}</td>
                                                        <td>{{account.first_name + " " + account.last_name}}</td>
                                                        <td>{{bill.currency + " " +
                                                            bill.Amount}}
                                                        </td>
                                                    </tr>
                                                </template>
                                                <template v-if="data.length === 0">
                                                    <tr>
                                                        <td colspan="7" class="center aligned">No request data.</td>
                                                    </tr>
                                                </template>
                                            </template>

this is my javascript

methods: {
                loadRequest: function () {
                    console.log(this.bill_no);
                    if (this.bill_no === "") {
                        alert("Nothing to search. Please enter bill number.");
                        return;
                    }

                    let self = this;

                    self.isLoading = true;

                    $.ajax({
                        url: "<?= Url::to(["/admin/bills/load-request"]) ?>",
                        method: 'GET',
                        type: 'GET',
                        dataType: 'json',
                        data: {order_number: this.bill_no}
                    }).done(function (data) {
                        if (data.status) {

                            self.data = data.data;

                        } else {
                            alert(data.message);
                            self.data = [];
                        }
                        console.log(data);
                        self.isLoading = false;
                    }).fail(function (jqXHR) {
                        if (jqXHR.responseJSON) {
                            alert("Nothing to search. Please enter bill number.");
                        } else {
                            alert("Nothing to search. Please enter bill number.");
                        }

                        self.isLoading = false;
                    });


                },

            },

Edit-----------------------------

I have solve my problem for displaying data from database by change the code in my controller

$data = Bill::find()
            ->where(['bill_no'=>$bill_number])
            ->asArray()
            ->all();

but I have a problem with a relationship as I still new with vue js.

my view

Mehdiable

My suggestion is that using of Pjax. In Pjax you have history of the AJAX events without refreshing the page.

And too, you can have clean code in your Action, View and JS file.

You can see help full in link : Yii2 Pjax Tutorial

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I get all my data from a table in my database and show it using php?

How can I get this data from database in PHP

How can I get data from MySql using PHP in my Xcode app?

How can I display only specific data in my gridview considering other database tables field in my database

In react-admin, how can i update my current view when i using fetch to get data?

How can I pull user input data as type "date" into my SQL database using PHP 7?

How can I get data from my database in LINQ C#?

How can i send data to a database from a view in Django?

How can I post my data that i get from SQL into divs in php

How can I display data from MYSQL database using HTML table from a PHP file?

how can i save data, retrieved from a url into my database

How can I sync my data from an external database in Rails?

How can I print data from my database while in QTableWidget?

how can i save XmL data from a URL into my database

how can i get form data validate it with javascript and send it to database using php

How can I access windows services or data from windows machine from my website using PHP?

How can I get the data from MySQL database based on the selected ID using bootstrap and Ajax?

How can i delete data from database with foreign key constraint in mysql using php pdo

How can I use the data in my Adapter to show it in my GridView?

How can i get a specific data from my dataset using SQL and PHPmyadmin?

How can i get my required data from array of objects using javascript?

how can I get my php array data to persist?

How can i Insert data to database using php and codeigniter

How can I get JSON data from a URL using PHP? I'm getting authentication failure

How can I get total user in a group from database by PHP

How can I get data from database in ruby

how I can get data from the firebase database without repeat

How can I get data from database into HTML table?

How can i get data from database based on the session?