volosoft / jtable

A JQuery plugin to create AJAX based CRUD tables.
http://www.jtable.org
1.1k stars 506 forks source link

New Feature:EditInline and ToolbarSearch (Multiple) #302

Open nubuntu opened 11 years ago

nubuntu commented 11 years ago

i just get problem in few days ago about my table, in dynamic filtering and dynamic editinline so i learn from @hikalkan codes,,then write this extension to jtable, get js in my repo and hope this help just simply example

editinline jquery.jtable.editinline.js

toolbarsearch jquery.jtable.toolbarsearch.js

get script at https://github.com/nubuntu/jtable/tree/master/lib/extensions

embed script at once

script type="text/javascript" src="asset/jquery-1.9.0.min.js"> script type="text/javascript" src="..asset/jquery-ui-1.10.0.custom/js/jquery-ui-1.10.0.custom.js"> script type="text/javascript" src="asset/jtable.2.2.1/jquery.jtable.js"> script type="text/javascript" src="jtable.2.2.1/extensions/jquery.jtable.editinline.js"> script type="text/javascript" src="asset/jtable.2.2.1/extensions/jquery.jtable.toolbarsearch.js">

just type editinline:{enable:true} to enabe editinline and type toolbarsearch:true enable toolbar search

    $('#StudentTableContainer').jtable({
        title: 'The Student List',
        paging: true, //Enable paging
        pageSize: 10, //Set page size (default: 10)
        sorting: true, //Enable sorting
        defaultSorting: 'Name ASC', //Set default sorting
        editinline:{enable:true},
        toolbarsearch:true,
        actions: {

...................................................... ........................................................

and in my data table its look like below,

datepicker for type:'date' ei1

dropdown for defined option ei2

textarea for type:'textarea' ei3

fancy checkbox(click toggle) for type:'checkbox' ei4

multiple toolbar search ts1

with reset button ts2

and php to support multiple search will look like this $db = NuDB::getObj();// $db is my mysql class to simplify crud, get it in my repo if you wanna ease code $offset = isset($_REQUEST['jtStartIndex']) ? $_REQUEST['jtStartIndex']:1 ;
$rows = isset($_REQUEST['jtPageSize']) ? $_REQUEST['jtStartIndex']:10 ; $sort = isset($_REQUEST['jtSorting']) ? $_REQUEST['jtSorting']:$db->primary.' desc';

    $q = $_REQUEST['opt']; // keyword/field values
    $opt = $_REQUEST['opt']; // fieldnames
    $where ='';
    if($q):
    for($i = 0; $i < count($opt); $i++):  
        $where[] = $opt[$i]." like '".$q[$i]."%'";
    endfor;
    $where = " where ".implode(" And ",$where);  
    endif;
    $q = "select count(*) FROM sometable".$where;
    $db->setQuery($q); 
    $total= $db->loadResult();  
    $q = "SELECT * FROM sometable".$where." order by ".$sort;  
    $items = $db->getList($q,$offset,$rows);            
    $jTableResult = array();
    $jTableResult['Result'] = "OK";
    $jTableResult['Records'] = $items;
    $jTableResult['TotalRecordCount'] = $total;
    die(json_encode($jTableResult));
absdirect commented 11 years ago

Can you further explain the last part of your post?

"and php to support multiple search will look like this"

I am testing your toobar script and it will not perform anything.

gbisheimer commented 11 years ago

Nice work nubuntu!. I've just ended writting my own jTableFilter extension because I overlooked your post. It would saved me a couple of hours of work. Cheers!

nubuntu commented 11 years ago

@absdirect you can use all of my class to prove, in my jtable folde, use example.jtable.php @gbisheimer i hope @hikalkan will merge this, but i have not seen him here

absdirect commented 11 years ago

And how can we customize the fields using your example.jtable.php format? ie. edit:false, list:false, title: "Whatever" ...etc

nubuntu commented 11 years ago

$student_name = array('title"=>"Name","edit"=>false); $student_address = array('title"=>"Addess","edit"=>tue); $table->fields['student_name'] = array_push($student_name); or $table->fields['student_name']['title'] = "Name"; $table->fields['student_name']['edit'] = false;

maybe thats a bit long code, but look easy and comfortable. next i will simplify code if many using it

absdirect commented 11 years ago

Any advice on adding toolbar items (http://www.jtable.org/ApiReference#genopt-toolbar) using your example.jtable.php method?

nubuntu commented 11 years ago

i just modify jtable.php and example.jtable.php , you can use toolbar like in example.jtable.php,see it there

Plopinoux commented 11 years ago

Hi dude, I have just found your work and it's amazing, it's really nice to you to share it with us :) But I have few issues to understand what is needed to use the search Toolbar I have downloaded your jtable-master folder and copy all libs on my project

On my .php I added ( i have already my own jtable ) :

I know is because I don't set the function but on your example.jtable.php i don't really understand what is needed, Do i have to use your "jtable.php" and "nudb.php" ?

Can you explain it to me ? anyway thx for the work :)

Plopinoux

nubuntu commented 11 years ago

jtable.php is a class used for generate javascript object to jquery.jtable.js,then build jtable user interface and nudb.php is a mysql class that working behind to support CRUD request,and it safety to use, you just need to configure host,user,and mysql password in nudb.php, and below how to get nudb.php work in jtable.php

//declare jtable class to variable $table $table = NuJTable::getObj(); // declare mysql class object to variable $db $db = NuDB::getObj(); // push database to work with jtable $table->($db,"tablename");//the last parameter is primary key, default is id ..... ..... ..... //here a line jtable use to listen all request to read,create,insert,delete,data $table->trigger();

if you using joomla you can simply push db class to jtable.php like below: ........ $db = JFactory::getDBO(); $table->($db,"tablename"); ...........

Plopinoux commented 11 years ago

Hi Nubuntu, First of all , thx for the answer :) But I still not understand all of your way to do this

Here is my code ( CRUD for a Center Table ) , i'm running Silverstripe CMS

I use 2 php files, one for actions : http://pastebin.com/927PvSwL and one for create CRUD table in js : http://pastebin.com/fZEpdBC1 I have a .ss file for the render but isnt really important here

Here is the display : http://screencast.com/t/i0vXhUafL5fh

Everything is working except the searchToolBar, what I have to get from the example.jtable.php to get this working ?

I know that my way isnt the best cause of the hardwritting in the code, maybe u can tell me how to modify my code to use your :)

In Advance thanks for the answer and if u wanna more details just ask :)

Cheers, Plopinoux

nubuntu commented 11 years ago

hey dude, thanks for your interest.... actually you can see my jtable.php and find below code to implement in your code function data(){ if(isset($_REQUEST['detail'])): $this->datadetail(); endif; $offset = isset($_REQUEST['jtStartIndex']) ? $_REQUEST['jtStartIndex']:1 ;
$rows = isset($_REQUEST['jtPageSize']) ? $_REQUEST['jtPageSize']:10 ; $q = $_REQUEST['q']; $sort = isset($_REQUEST['jtSorting']) ? $_REQUEST['jtSorting']:$this->db->primary.' desc'; $opt = $_REQUEST['opt']; $where =''; if($q): if(!is_array($q)): $where = " where $opt like '%$q%'"; else: for($i = 0; $i < count($opt); $i++):
$where[] = $opt[$i]." like '%".$q[$i]."%'"; endfor; $where = " where ".implode(" And ",$where);
endif; endif; $q = "select count() FROM ".$this->table.$where; $this->db->setQuery($q); $total= $this->db->loadResult();
$q = "SELECT \
FROM ".$this->table.$where." order by ".$sort;
$items = $this->db->getList($q,$offset,$rows);
$jTableResult = array(); $jTableResult['Result'] = "OK"; $jTableResult['Records'] = $items; $jTableResult['TotalRecordCount'] = $total; die(json_encode($jTableResult)); }

and maybe you can modify your list action like this ///up to you if you wanna do with $_GET or $_REQUEST, both are the same if ($_GET["action"] == "list") { $offset = isset($_REQUEST['jtStartIndex']) ? $_REQUEST['jtStartIndex']:0 ;
$rows = isset($_REQUEST['jtPageSize']) ? $_REQUEST['jtPageSize']:10 ; $q = $_REQUEST['q']; $sort = isset($_REQUEST['jtSorting']) ? $_REQUEST['jtSorting']:'ID desc'; $opt = $_REQUEST['opt']; $where =''; if($q): if(!is_array($q)): $where = " where $opt like '%$q%'"; else: for($i = 0; $i < count($opt); $i++):
$where[] = $opt[$i]." like '%".$q[$i]."%'"; endfor; $where = " where ".implode(" And ",$where);
endif; endif;

                    //Get record count
            $SQL = "SELECT COUNT(*) AS RecordCount FROM Center $where";
            $sth0 = $con->prepare("$SQL");
            $sth0->execute();
            $row0 = $sth0->fetch(PDO::FETCH_ASSOC);
            //var_dump($row0);die();
            $recordCount = $row0['RecordCount'];

            //Get records from database
            //$result = mysql_query("SELECT * FROM Member ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
            $SQL = "SELECT * FROM Center $where ORDER BY $sort LIMIT $offset,$rows" ;
            $sth1 = $con->prepare("$SQL");
            $sth1->execute();

            //Add all records to an array
            $rows = array();
            //while($row = mysql_fetch_array($result))
            while($row1 = $sth1->fetch(PDO::FETCH_ASSOC))
            {
                $rows[] = $row1;
            }
            //var_dump($rows);die();
            //Return result to jTable
            $jTableResult = array();
            $jTableResult['Result'] = "OK";
            $jTableResult['TotalRecordCount'] = $recordCount;
            $jTableResult['Records'] = $rows;
            print json_encode($jTableResult);
        }
Plopinoux commented 11 years ago

Here is my Code with yours : http://pastebin.com/2uePUg7N

on lines 10 to 26 ( + modifs line 28 '$where' and line 38 ' changing ORDER by ' )

It still not working but i think it's because i don't use the function "datadetail()" of your jtable.php ( it missed me the "$q" and "$opt" var )

But i'm still using my way on that case, and as your work is better than mine, i would like to use yours

If I may, i really appreciate if you can give me the example of my code in your way ( ie using your jtable + my AdminCentrePage.php and AdminCentreActions.php but in your way )

For now i don't really understand where is the definition of fields etc in your way ^^ , all actions are in jtable.php but where are the definition of your table ? ( like table Center for me with the AdminCentrePage.php )

Anyway thanks to take time to help me :) I'm really grateful

I give you my skype if you wanna do Instant Chat, Maybe It will be easier to understand each other :) skype nickname : dreddfullmetal

See ya dude,

Plopinoux

nubuntu commented 11 years ago

$this->datadetail is used for child table,so its no need in this case, you just miss a line at $sort = isset($_GET['jtSorting']) ? $_GET['jtSorting']:$this->db->primary.' desc'; change with $sort = isset($_GET['jtSorting']) ? $_GET['jtSorting']:'your_primary _key_table asc/desc'; //example:'ID desc'

if you wanna use in my way yo have to changeAdmin Page Controller like this class AdminCentresPage_Controller extends Page_Controller {

function init() {
    parent::init();
    //requeire needed class
    require_once("nudb.php");
    require_once("jtable.php");

    // first set up your db configuration in nudb.php
    $db = NuDB::getObj();
    $table = NuJTable::getObj();
    $table->toolbarsearch=true;
    $table->setUrl($_SERVER['PHP_SELF']);//use $table->setUrl($_SERVER['PHP_SELF'].'?') if doesn't work
    $table->setTitle('Tables  des centres');
    //set table from database setTable("DB Resource","Table Name","Primary key, default=id")
    $table->setTable($db,"Center","ID");
    //trigger all request
    $table->trigger();

    Requirements::javascript('jtable.2.3.0/scripts/jquery-1.6.4.min.js');
    Requirements::javascript('jtable.2.3.0/scripts/jquery-ui-1.8.16.custom.min.js');
    Requirements::javascript('jtable.2.3.0/scripts/jtable/jquery.jtable.js');
    //Requirements::javascript('flform/javascript/AdminCentres.js');
    Requirements::javascript('jtable.2.3.0/scripts/jtable/extensions/jquery.jtable.toolbarsearch.js');
    Requirements::css("jtable.2.3.0/themes/redmond/jquery-ui-1.8.16.custom.css");
   Requirements::css("jtable.2.3.0/scripts/jtable/themes/lightcolor/blue/jtable.css");

Requirements::customScript("

            $(document).ready(function () {
                ".$table->render()."

            });

"); print $table->gethtml(); }

}

Plopinoux commented 11 years ago

Thx for your quick answer :)

Anyway with your way, where do you define fields like what i do in my AdminCentrePage ? these for example : ID: { key: true, create: false, edit: false, list: false }, name: { title: 'Nom du centre', width: '25%' }, contact_ref: { title: 'contact_ref',
list : false }, streetLocation: { title: 'adresse', list : false },

nubuntu commented 11 years ago

the error might be here $SQL = "SELECT COUNT() AS RecordCount FROM Center $where"; $SQL = "SELECT * FROM Center $where ORDER BY $sort LIMIT $offset,$rows" ; remove space before $where $SQL = "SELECT COUNT() AS RecordCount FROM Center$where"; $SQL = "SELECT * FROM Center$where ORDER BY $sort LIMIT $offset,$rows" ;

field name and type generate automatically by jtable.php, if you want to define fields just write your custom after $this->setTable() command ...................... $table->setTable($db,"Center","ID");

$table->fields['ID']=array("list"=>false); $table->fields['name']=array("title"=>"Nom du centre");

//OR you can do with

$custom = array( "ID"=>array("list"=>false), "name"=>array("title"=>"Nom du centre") ); $table->fields = array_merge($table->fields,$custom);

//and trigger always in the end $table->trigger();

Plopinoux commented 11 years ago

hum I guess I forget something cause it still not working,

There is a button to launch the search or is dynamically ? like as we write something into the search input , the search begin ?

here is my adminCentresAction : http://pastebin.com/kgt3dhqD Here is my adminCentresPage ; http://pastebin.com/eVsG5WFr

Here is my behavior : http://screencast.com/t/8lBmbdT8Jrh I push Enter to try to launch the search but nothing happens ^^

Moreover i tried your way but the table isnt rendered, the div jtable-data exist but isnt display even if i add it into my .ss file ( render file with silverstripe cms ) , i will retry further later :)

nubuntu commented 11 years ago

its running dynamically you can see working example at http://jtable.noercholis.com/member.php i suggest youtu use inspect element in chrome or firebug in firefox,to see javasricpt error, tellme the error and i will try to solve your problem

Plopinoux commented 11 years ago

Thx for the example but why this musik oO It's the big deal ^^ i don't have errors with Firebug, even when i click "Enter" when i'm on the search input ^^

nubuntu commented 11 years ago

you can see how the music work on edit and create form and delete event, the event is onchange,so what happen when you leave the input?

Plopinoux commented 11 years ago

Hum, it launch this url : AdminCentresActions.php?action=list&jtStartIndex=0&jtPageSize=15&jtSorting=name%20ASC

so this code ;

if ($_GET["action"] == "list") {

            $offset = isset($_GET['jtStartIndex']) ? $_GET['jtStartIndex']:1 ;  
    $rows = isset($_GET['jtPageSize']) ? $_GET['jtPageSize']:10 ;
    $q = $_GET['q'];
    $sort = isset($_GET['jtSorting']) ? $_GET['jtSorting']:'name desc';
    $opt = $_GET['opt'];
    $where ='';
    if($q):
        if(!is_array($q)):
            $where = " where $opt like '%$q%'";
        else:
            for($i = 0; $i < count($opt); $i++):  
                $where[] = $opt[$i]." like '%".$q[$i]."%'";
            endfor;
            $where = " where ".implode(" And ",$where);  
        endif;
    endif;
                //Get record count
    $SQL = "SELECT COUNT(*) AS RecordCount FROM Center$where";
            $sth0 = $con->prepare("$SQL");
            $sth0->execute();
            $row0 = $sth0->fetch(PDO::FETCH_ASSOC);
            //var_dump($row0);die();
    $recordCount = $row0['RecordCount'];

    //Get records from database
    //$result = mysql_query("SELECT * FROM Member ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
    //$SQL = "SELECT * FROM Center ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] ;
            $SQL = "SELECT * FROM Center$where ORDER BY $sort LIMIT $offset,$rows" ;
            $sth1 = $con->prepare("$SQL");
            $sth1->execute();

    //Add all records to an array
    $rows = array();
    //while($row = mysql_fetch_array($result))
            while($row1 = $sth1->fetch(PDO::FETCH_ASSOC))
    {
        $rows[] = $row1;
    }
            //var_dump($rows);die();
    //Return result to jTable
    $jTableResult = array();
    $jTableResult['Result'] = "OK";
    $jTableResult['TotalRecordCount'] = $recordCount;
    $jTableResult['Records'] = $rows;
    print json_encode($jTableResult);
        }

and it displays all the centers without my special search i don't think i get the $q and $opt

Plopinoux commented 11 years ago

Yep after tests, i don't get the $q

nubuntu commented 11 years ago

ooops i think you have to replace all your $_GET with $_REQUEST, cause $opt and $q sent by $_POST, sorry my wrong, you could use $_POST['opt'],$_POST['q'] or like me that use $_REQUEST['opt'].$_REQUEST['q']

Plopinoux commented 11 years ago

Yes :) it's working ^^ Thanks a lot dude for all the help ^^

Yeah now i'll try to use your way ^^ I think i will be back to you soon but I leave you alone for today xD I have already sufficiently bothered you for one day xD

cheers, Plopinoux

Plopinoux commented 11 years ago

Hey there :)

I have a little question for you Nubuntu ^^

As you can see here : http://screencast.com/t/iHVhUQhq7 ( Sorry for the hide but I can't show personal information ^^ i'm sure you understand :)

So here is my jtable with the search toolbar but like you see in the screenshot, there is a red rectangle where I add an icon to display another table.

My whish is to not render this search input field for this field, do you know if there is a way ? ( I tried toolbarsearch : false in my field but it doesn't work )

And optionaly, i wanna center the image with the man, i tried with cssClass attribut but i didn't succeed maybe you have some tips to give about this ^^

Thanks in advance, Plopinoux

nubuntu commented 11 years ago

Thanks for advice, i will fix it in few moments, are you use jtable php? On Apr 8, 2013 9:59 PM, "Plopinoux" notifications@github.com wrote:

Hey there :)

I have a little question for you Nubuntu ^^

As you can see here : http://screencast.com/t/iHVhUQhq7 ( Sorry for the hide but I can't show personal information ^^ i'm sure you understand :)

So here is my jtable with the search toolbar but like you see in the screenshot, there is a red rectangle where I add an icon to display another table.

My whish is to not render this search input field for this field, do you know if there is a way ? ( I tried toolbarsearch : false in my field but it doesn't work )

And optionaly, i wanna center the image with the man, i tried with cssClass attribut but i didn't succeed maybe you have some tips to give about this ^^

Thanks in advance, Plopinoux

— Reply to this email directly or view it on GitHubhttps://github.com/hikalkan/jtable/issues/302#issuecomment-16055343 .

nubuntu commented 11 years ago

hey dude i have updated jquery.jtable.toolbarsearch.js get new js and type searchable:false in your field that dont wont to appear input text example: name: { title: 'Nom du centre', width: '25%', searchable:false }

default value is true

Plopinoux commented 11 years ago

Hey dude :)

I just tested and it's working perfectly :) really thanks for this improvment

( to answer you, no i'm not using jtable.php cause my work is very specific and I don't have the time right now to reformat my code to work with your jtable.php but as soon as i have the time i will do it ^^ )

Anyway this jtable is going better day by day ^^ Continue like this

Cheers, Plopinoux

Plopinoux commented 11 years ago

Hi dude :)

Sorry to contact you here but as there is no message sytem on github ( or i din't find it ) and that i don't really know where to put it, i write it here and i hope you will see it ^^

My problem is the next, I wanna localize the title of my columns inside my jtable

For example now i have this

AddProtocol: { title: 'Ajouter un Protocole',

type: 'list', options : 'flform/code/AdminInvestigateursActions.php?action=GetProtocoles&UserId='+UserId, edit: false, list: false

}

As you see the title is in French but if my user is english I wanna "Add a protocol".

I already use the localisation for the rest of the Jtable but i can't figure out for Title, even for the name of the Jtable example of a jtable name : title: 'Protocoles de l\'investigateur '+NomInvestigateur,

Do you know a way to localize them ?

I use this to overide addNewRecord but isn't enough cause is to general ( by default, in english : addNewRecord : 'Add new record' and i wanna 'Add new Protocol'

messages : { addNewRecord : 'Ajouter un protocole' },

Can I do something like that :

messages : { addNewRecord : 'Ajouter un protocole' fields_ID_Title : "what a want" fields_AddProtocol_Title : "Add Protocol" etc .. ? },

I hope you will light me :) Thanks in advance

Plopinoux

xhava commented 11 years ago

hi my friend u know i have a problem with filtering in jtable since months ago. i just want to do filtering like in the example wich is showed in the website jtable.org but in that example the code in the server side is on asp.net but i just wanna do that with php.

please help me . i will really appreciate it.... thanks

Plopinoux commented 11 years ago

Hey dude :) Sorry i just saw your post, if i can help you i will :)

If i understand what you mean, you have a problem with the search pluging into the jtable ? right ?

First of all, you have to download the last trunk of jtable including the toolbarsearch.js

2) in your php file, in Init function you have to require this js

like that ( i'm working with Silverstripe CMS but i guess is pretty much the same with another CMS ) :

function init() { parent::init(); Requirements::javascript('jtable.2.3.0/scripts/jquery-1.6.4.min.js'); Requirements::javascript('jtable.2.3.0/scripts/jquery-ui-1.8.16.custom.min.js'); Requirements::javascript('jtable.2.3.0/scripts/jtable/jquery.jtable.js'); Requirements::javascript('jtable.2.3.0/scripts/jtable/extensions/jquery.jtable.toolbarsearch.js'); Requirements::css("jtable.2.3.0/themes/redmond/jquery-ui-1.8.16.custom.css"); Requirements::css("jtable.2.3.0/scripts/jtable/themes/lightcolor/blue/jtable.css"); }

3) in your JS script which contain the declaration of your table, activate your searchToolBar

like that :

$(document).ready(function () {

        //Prepare jTable
        $('#CentresTableContainer').jtable({
            title: $TitreTable,
            paging: true,
            pageSize: 15,
            sorting: true,
            defaultSorting: 'name ASC',

                            toolbarsearch:true,

                             messages : {
                                addNewRecord : $addCenter
                            },
            actions: {
                listAction: 'flform/code/AdminCentresActions.php?action=list',
                createAction: 'flform/code/AdminCentresActions.php?action=create',
                updateAction: 'flform/code/AdminCentresActions.php?action=update'

            },
            fields: {
                ID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },

4 ) In your actions file ( I have 2 php files for 1 table, one with Init function + custom JS containaing the jtable above and another one containing the actions )

here is the list action ( the search is only for the list action )

if ($_GET["action"] == "list") { / * Ces quelques lignes servent a implémenter la recherche automatique sur la jtable. * These few line are used to implement the automatique search on the jtable / $offset = isset($_GET['jtStartIndex']) ? $_GET['jtStartIndex']:1 ;
$rows = isset($_GET['jtPageSize']) ? $_GET['jtPageSize']:10 ; $q = $_POST['q']; $sort = isset($_GET['jtSorting']) ? $_GET['jtSorting']:'name desc'; $opt = $_POST['opt'];

    $where ='';
    if($q):
        if(!is_array($q)):
            $where = " where $opt like '%$q%'";
        else:
            for($i = 0; $i < count($opt); $i++):  
                $where[] = $opt[$i]." like '%".$q[$i]."%'";
            endfor;
            $where = " where ".implode(" And ",$where);  
        endif;
    endif;
                 /*
     * Fin du code de recherche
     * End of search code

     * Requête de selection permettant de récupèrer le nombre de centres
     * Request to get the count of centers ( or what your what )
     */
    $SQL = "SELECT COUNT(*) AS RecordCount FROM Center$where";
            $sth0 = $con->prepare("$SQL");
            $sth0->execute();
            $row0 = $sth0->fetch(PDO::FETCH_ASSOC);
            //var_dump($row0);die();
    $recordCount = $row0['RecordCount'];

    /*
     * Récupèration des investigateurs
     */
            $SQL = "SELECT * FROM Center$where ORDER BY $sort LIMIT $offset,$rows" ;
            $sth1 = $con->prepare("$SQL");
            $sth1->execute();

    //Add all records to an array
    $rows = array();
    /*
     * Pour chaque investigateur, on récupère toutes ses informations et on les range dans un tableau
     */
            while($row1 = $sth1->fetch(PDO::FETCH_ASSOC))
    {
        $rows[] = $row1;
    }
            /*
     * On sauvegarde le tout dans un tableau '$jTableResult'
     * Puis on l'encode en Json pour l'afficher dans la jtable
     */
    $jTableResult = array();
    $jTableResult['Result'] = "OK";
    $jTableResult['TotalRecordCount'] = $recordCount;
    $jTableResult['Records'] = $rows;
    print json_encode($jTableResult);
        }

Is just an example of one of my list actions, you will have to modify it to follow your code and that's all

I hope it will help you,

feel free to ask me if isn't clear or if you wanna more informations

see ya,

Plopinoux

xhava commented 11 years ago

hey dude plopinoux sorry i had not seen your post. thanks for helping me . i´m gonna try to do what u told me . if i have a problem i will tell you what is wrong . really a lot of thanks my friend. we are in touch

xhava commented 11 years ago

hi plopinoux i think that i don´t understand very well , cause i am not using some CMS , i am just using html javascript and php

lalacollie commented 11 years ago

HI ,nubuntu.. i try to code that --->

                         title: 'Table of people',
                         editinline:{enable:true},

            messages : {
                            addNewRecord : '+add new record'

                        },
            actions: {
                listAction: 'PersonActions.php?action=list',
                createAction: 'PersonActions.php?action=create',
                updateAction: 'PersonActions.php?action=update',
                deleteAction: 'PersonActions.php?action=delete'
            },

but it does't any work

sugeng86 commented 11 years ago

hi nubuntu i am newbie i try your code with complete library but nothing happen,no data display, maybe you can explain me why? thank you before

xhava commented 11 years ago

hi please someone can help me whit the plugin to validate forms. i have a field in my database wich is unique but how i can validate that... please .. i read that i have to create an array from the server and then i have to print it with json_encode but what structure the array has to have

Dunde commented 11 years ago

@nubuntu Seems like there is a minor bug in the editinline extension. The defaultDateFormat or displayFormat doesn't change the format when the date is initially shown on the table. It is shown as it is in the database.

Need to set the format for the fieldValue somewhere outside the .click() function.

        var self = this;
        var field = this.options.fields[fieldName];
        var fieldValue = record[fieldName];
        var displayFormat = field.displayFormat || this.options.defaultDateFormat;

        // Parse the fieldValue and set the format
        fieldValue = $.datepicker.formatDate(displayFormat, self._parseDate(fieldValue)); 

        var defaultval = (fieldValue) ? fieldValue :'&nbsp;&nbsp;&nbsp;';
        var $txt = $('<div>' + defaultval + '</div>');
        $txt.click(function(){
        ...

This solution at least seems to work fine.

Dunde commented 11 years ago

Actually looks like still some problems persist.

Dunde commented 11 years ago

The problem persisted when first used inline editing for editing data and afterwards using the normal edit form.

To solve this I had to parse and format the date again inside the .click() function, so the record[fieldName] value is of proper format for jTable.

If both inline edit and normal edit form are used in a table the date handling seems to get in trouble without the extra parsing and reparsing.

Might be that theres an easier way to solve this, but this was the most obvious I guess.

fredyinstr commented 11 years ago

Nubuntu, thanks for your excellent post, I have tested the example.jtable.php and all work fine, however I'd like know How can I do for export to excel the filtered data.

crynos commented 11 years ago

@nubuntu Excellent job! Thank you.

I have some rows that have some empty cels on it. I can edit in line the information on cells that have some information, but if the cell is empty, i cant edit in line. There's a way to do this ?

crynos commented 11 years ago

Forget it... I was clicking on the middle of the cell.. i've tried clicking on the left side of it, and works.

Maybe would be nice if we can click anywhere on the cell. =)

crynos commented 11 years ago

Now, a real problem. When i edit a cell, updates the value of it, BUT, clear the rest... i mean, empty all the rest of the cells ... Am i doing something wrong?

Filozuz commented 11 years ago

---------------------------------------------------------------------------------------------------------

I have this code

//crea instancia y obtiene los valores del ini CIP // $CI = new ConfigIni; $Mat = $CI->lee_ini($CI->INI); $Host = $Mat['DBServidor']; $Ruta = $Mat['DBBaseDatos']; $TbManBD = $Mat['MANBD']; $Ruta = str_replace('\','\',$Ruta);

//Open database connection interbase
$Conex = ibase_connect($Host .":". $Ruta , $CI->USER, $CI->PASS);

//var para los queries
$Query = "";

//Obtiene los registros (listAction)
if($_GET["action"] == 'list')
{

    #---------------------------------------------------
    $offset = isset($_GET['jtStartIndex']) ? $_GET['jtStartIndex']:1 ;  
    $rows = isset($_GET['jtPageSize']) ? $_GET['jtPageSize']:10 ;
    $q = $_GET['q'];
    $sort = isset($_GET['jtSorting']) ? $_GET['jtSorting']:' Id desc';
    $opt = $_GET['opt'];
    $where ='';
    if($q):
            if(!is_array($q)):
                    $where = " where $opt like '%$q%'";
            else:
                    for($i = 0; $i < count($opt); $i++):  
                            $where[] = $opt[$i]." like '%".$q[$i]."%'";
                    endfor;
                    $where = " where ".implode(" And ",$where);  
            endif;
    endif;
    #---------------------------------------------------

    //Obtiene el numero de registros
    //
    $Query = "SELECT COUNT(*) AS RecordCount FROM ". $TbManBD ." $where;";
    $result = ibase_query($Conex, $Query);
    $row = ibase_fetch_assoc($result);
    $recordCount = "".$row['RECORDCOUNT']."";

    //Get records from database
    //
    //compara si viene desde un child, si no muestra todos
    if(isset($_GET["ManBd"]))
        $Query = "SELECT * FROM ". $TbManBD ." WHERE Id = ". $_GET["ManBd"] .";";
    else
        $Query = "SELECT FIRST " . $_GET["jtPageSize"] . " SKIP " . $_GET["jtStartIndex"] . 
                 " * FROM ". $TbManBD ." $where ORDER BY ". $_GET["jtSorting"] .";";

    $result = ibase_query($Conex,$Query);

    //Agrega los reistros en un array
    $rows = array();
    while($row = ibase_fetch_assoc($result))
    {
        $rows[] = $row;
    }

    //Regresa los resultados al jTable
    $jTableResult = array();
    $jTableResult['Result'] = "OK";
    $jTableResult['TotalRecordCount'] = $recordCount;
    $jTableResult['Records'] = $rows;
    print json_encode($jTableResult);       

--------------------------------------------------------

But the code lines

$q = $_GET['q'];

$opt = $_GET['opt'];

Don´t work, i don´t get the values of $_GET['q'] and $_GET['opt']

Somebody can help me with this!

Filozuz commented 11 years ago

and my scripts

<link href="jtable/Scripts/jtable/themes/lightcolor/blue/jtable.css" rel="stylesheet" type="text/css" />
<script src="jtable/scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="jtable/scripts/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script src="jtable/Scripts/jtable/jquery.jtable.js" type="text/javascript"></script>
<script src="jtable/Scripts/jtable/localization/jquery.jtable.es.js" type="text/javascript"></script>
<script src="jtable/Scripts/jtable/extensions/jquery.jtable.editinline.js" type="text/javascript"></script>
<script src="jtable/Scripts/jtable/extensions/jquery.jtable.toolbarsearch.js" type="text/javascript"></script>

-------------------------------------------------

            <script type="text/javascript">

                $(document).ready(function () {

                    //Prepare jTable
                    $('#CatManejadorBD').jtable({
                        title: 'Manejadores',
                        paging: true,
                        pageSize: 5,
                        sorting: true,
                        defaultSorting: 'ID ASC',
                        editinline:{enable:true},
                                toolbarsearch:true,
                        actions: {
                            listAction: 'ManejadorBD.php?action=list',
                            createAction: 'ManejadorBD.php?action=create',
                            updateAction: 'ManejadorBD.php?action=update',
                            deleteAction: 'ManejadorBD.php?action=delete'
                        },
                        fields: {
                            ID: {
                                key: true,
                                create: false,
                                edit: false,
                                list: true,
                                title: 'Codigo'
                            },
                            NOMBRE: {
                                title: 'Nombre',
                                width: '40%'
                            }
                        }
                    });

                    //Load person list from server
                    $('#CatManejadorBD').jtable('load');

                });

            </script>
Filozuz commented 11 years ago

and i use

<link href="jtable/themes/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
<link href="jtable/Scripts/jtable/themes/lightcolor/blue/jtable.css" rel="stylesheet" type="text/css" />
<script src="jtable/scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="jtable/scripts/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script src="jtable/Scripts/jtable/jquery.jtable.js" type="text/javascript"></script>
<script src="jtable/Scripts/jtable/localization/jquery.jtable.es.js" type="text/javascript"></script>
<script src="jtable/Scripts/jtable/extensions/jquery.jtable.editinline.js" type="text/javascript"></script>
<script src="jtable/Scripts/jtable/extensions/jquery.jtable.toolbarsearch.js" type="text/javascript"></script>
Filozuz commented 11 years ago

don't works not with post or to request

hostwu commented 11 years ago

Hi, I tried to implement your add-on that seems very nice. I've two problems : It doesn't respect de "visibility:hidden" and show every cell. After the third column, i've the "content -1" in the cell.

Have you ever seen it? I've tried to edit yourcode myself but no success. Thanks in advance

Filozuz commented 11 years ago

somebody know why don't work the $_GET['q'] / $_GET['opt'] $_POST['q'] / $_POST['opt'] $_REQUEST['q'] / $_REQUEST['opt']

i need help soon!

Filozuz commented 11 years ago

i can work now

this is my code

//para realizar la busqueda // $where = '';

    //verifica si hay texto a buscar
    //
    if(isset($_POST['q']))
    {
        //envia el textoa buscar y el campo en que buscar
        $where = $BD->JTGenFiltro($_POST['q'], $_POST['opt']);
    }       

    //Obtiene el numero de registros
    //
    $Query = "SELECT COUNT(*) AS RecordCount FROM ". $TbfClien ." $where;";

and

-----------[GENERA FILTRO PARA EL JTABLE]-------------

    //
    public function JTGenFiltro($B, $C, $T = 1)
    {
        //$B es el texto a buscar en la BD
        //$C es el campo en que se busca
        //$T es el tipo
        //si $T == 1: inicia con WHERE
        //si $T == 2: inicia con AND
        $where = "";

        //verifica si hay datos para iniciar el where
        //
        if($B)
        {
            //si es una simple cadena o un solo campo
            //
            if(!is_array($B))
            {
                if($T == 1)
                    $where = " WHERE UPPER($C) LIKE UPPER('%$B%')";
                else
                    $where = " AND UPPER($C) LIKE UPPER('%$B%')";
            }
            else
            {
                //si son varios campos
                //
                for($i = 0; $i < count($C); $i++)
                {
                    $where[] = "UPPER(".$C[$i].") LIKE UPPER('%".$B[$i]."%')";
                }

                if($T == 1)
                    $where = " WHERE ".implode(" AND ",$where);  
                else
                    $where = implode(" AND ",$where);  
            }
        }

        return $where;
    }
    #-Fin de funcion-#
Ragearo commented 11 years ago

nubuntu,

Good bit of code there. Very glad someone has taken up inline editing for this project, as it's my personal favorite grid based jquery/ajax editor, and it seems as though hikalkan has slowed down work on it.

I made a few improvements (in my opinion, of course). Firstly, I prefer having the inline edit trigger when clicking on the td rather than the small area of text. Rather than re-write a bunch of your code, though, I found this bit of css to work for that implementation.

   .jtable td span {
       display:block;
   }
   .jtable td span:hover {
       cursor:pointer;
   }

Also, your code does not work with the intended stock method of form submission with jtables. This may stem from your using a php backend, I'm not sure. Essentially, the entire form is to be submitted, not just the fields that have changed. Again though, a simple fix. Rather than set the postData variable to an empty object, you simply need to use the record object provided to the functions

                    //var postData = {};
                    var postData = record;

Hope this helps any others implementing your code. It's very smooth and very easy to manipulate to fit anyone's needs.