Code Monkey home page Code Monkey logo

Comments (3)

monkenWu avatar monkenWu commented on August 12, 2024

Happy Lunar New Year.

In the TableIgniter, setOutput() allows you to transmit arrays consists of the strings and anonymous function. If the array includings anonymous function, you should be aware of these three hints down below:

  1. TableIgniter will process every data fetched from the database on by one, and every time it will process the anonymous function you transferred.
  2. The anonymous function must only have a single parameter, and the parameter should be according to the database. This means you can do the logical judgments you need and the preprocessing for each row of data
  3. The return of the anonymous function must be a String, because the TableIgniter will combine the results into the frontend DataTables.

I made some changes to the codes you provided:

public function fetchProjectData()
{
    $table = new TablesIgniter();
    $table->setTable($this->projectModel->noticeTable())
        ->setDefaultOrder('project_name', 'ASC')
        ->setOrder([
            'project_name', 'client_name', 'pm_name',
            'start_date', 'finish_date', 'project_status', null
        ])
        ->setSearch(['project_name', 'client_name', 'pm_name', 'project_status'])
        ->setOutput([
            'project_name', 'client_name', 'pm_name', 'start_date',
            'finish_date', $this->projectStatus(), $this->projectModel->button()
        ]);
    return $table->getDatatable();
}

public function projectStatus()
{
    $closureFun = function ($row) {
        // $row should belong to the query results.
        if ($row['project_status'] == 'hold') {
            return '<span class="badge rounded-pill bg-primary">Hold</span>';
        } else {
            return '<button type="button" class="btn btn-info">Detail</button>'; 
        }
    }
    return $closureFun;
}

from tablesigniter.

firazyn avatar firazyn commented on August 12, 2024

Issue solved. Thank you!
I will close this thread.

from tablesigniter.

AnusiyaAnu avatar AnusiyaAnu commented on August 12, 2024

Hi

public function projectStatus()
{
$closureFun = function ($row) {
// $row should belong to the query results.
if ($row['status'] == '1')
{
return 'Hold';
} else {
return 'Detail';
}
}
return $closureFun;
}

getting syntax error, unexpected token "return"

Thanks

from tablesigniter.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.