Code Monkey home page Code Monkey logo

Comments (5)

benhe84 avatar benhe84 commented on August 12, 2024 1

But we will encounter a question here, if we input any string in the search funcition key of the Datatables, the where query set inside the noticeTable will become invalid.

That was the Problem! This Problem can be Prevented by changing the TablesIgniter.php

TablesIngiter.php

Edit the function extraConfig
Surround the foreach ($this->searchLike as $key => $field) in the with
$bui->groupStart(); and $bui->groupEnd();
so that it looks like:

if(!empty($_POST["search"]["value"])){
   $bui->groupStart();
   foreach ($this->searchLike as $key => $field) {
      if($key == 0){
         $bui->like($field,$_POST["search"]["value"]);
      }
      else{
        $bui->orLike($field,$_POST["search"]["value"]); 
      }
   }    
   $bui->groupEnd();
   }

If you surround the forech with a groupStart() and a groupEnd() the query inside the notice Table keeps valid.

from tablesigniter.

benhe84 avatar benhe84 commented on August 12, 2024

I solved the Problem. Surround the foreach ($this->searchLike as $key => $field) in the function extraConfig with
$bui->groupStart(); and $bui->groupEnd();
so that it looks like:

if(!empty($_POST["search"]["value"])){ $bui->groupStart(); foreach ($this->searchLike as $key => $field) { if($key == 0){ $bui->like($field,$_POST["search"]["value"]); }else{ $bui->orLike($field,$_POST["search"]["value"]); } } $bui->groupEnd(); }
Then only Entries from the Builder are shown.

from tablesigniter.

monkenWu avatar monkenWu commented on August 12, 2024

Hi there !

Can you provide part of your configuration inside your Controller relating to the TableIgniter?
This really helps me debug.

According to your question, I tried to revert the possible situation. Take the sample codes as an example:

controller

public function fullTable(){
    $model = new HomeModel();
    $table = new TablesIgniter();
    $table->setTable($model->noticeTable())
          ->setDefaultOrder("id","DESC")
          ->setSearch(["title","date"])
          ->setOrder([null,null,"date"])
          ->setOutput([$model->button(),"title","date"]);
    return $table->getDatatable();
}

Model

public function noticeTable(){
    $builder = $this->db->table("news")
                    ->where('date','2020-01-04');
    return $builder;
}

According to the codes above, the builder inside noticeTable will only illustrate the date content as 2020-01-04.
But we will encounter a question here, if we input any string in the search funcition key of the Datatables, the where query set inside the noticeTable will become invalid.

The cause of this question is the configuration of the Controller have confilct with the builder.
Lets take a look at the 6th line of the sample Controller: ->setSearch(["title", "date"]).

In the TablesIgniter, the builder you transmit will become the foundation of all SQL Query. If you have already defined a rule that can filter some field with Where statement inside the builder, then the field should not be seen in the configuration of setSearch() of the TablesIgniter.

If we revise the ->setSearch(["title","date"]) inside the sample program into ->serSearch(["title"]), you will find out that everything works normally.

from tablesigniter.

monkenWu avatar monkenWu commented on August 12, 2024

OK,I get it!
I will fix this problem in the next version.
Thank you for your feedback!

from tablesigniter.

monkenWu avatar monkenWu commented on August 12, 2024

Hi, you can update to the v1.2.0 version, which fixes the above problem.

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.