Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
need help:get confuse about delete and searching
30/01/2010
13:32
Avatar
Candrairawan78
Indonesia
Member
Members
Forum Posts: 39
Member Since:
30/01/2010
sp_UserOfflineSmall Offline

Dear Tony,

Would you mind to help me to solve my grid, please? i have look around this forum and i am still confuse.

1. the delete function don`t work, how to implement the delete function on multi select?

2. I can`t implement searching server code on multi search toolbar, would you give me an example code pleaseeeee.....?Cry

would you mind to take a look on my script and tell me where is the fault..... Thank you very much for your helpSmile

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Data Pegawai</title>
 
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.7.2.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
 
<style>
html, body {
    margin: 0;
    padding: 0;
    font-size: 75%;
}
</style>
 
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="js/jquery.jqGrid.min.js"></script>
 
<script type="text/javascript">
jQuery(document).ready(function(){
  var mygrid =
  jQuery("#list").jqGrid({
    url:'tablejson.php', <!--The url of the file where to get the data-->
    datatype: 'json', <!--Defines what type of information to expect to represent data in the grid.-->
    mtype: "POST",
    colNames:['Id','Name', 'Address','Telp','Level','Shift', 'Salary','Date'],
    colModel :[
      {name:'noktp'   , index:'noktp'   , width:80                                                 , editable:true, editoptions:{size:20}, editrules:{required:true, number:true}, formoptions:{elmprefix:"(*)"}},
      {name:'nama'    , index:'nama'    , width:100                                                , editable:true, editoptions:{size:25}, editrules:{required:true}, formoptions:{elmprefix:"(*)"}},
      {name:'alamat'  , index:'alamat'  , width:160, align:'right'                                 , editable:true, editoptions:{size:25}, editrules:{required:true}, formoptions:{elmprefix:"(*)"}},
      {name:'telp'    , index:'telp'    , width:60, align:'right'                                  , editable:true, editoptions:{size:25}, editrules:{required:true}, formoptions:{elmprefix:"(*)"}},
      {name:'posisi'  , index:'posisi'  , width:50, align:'right'                                  , editable:true, editoptions:{size:25}, formoptions:{elmprefix:"(*)"}},
      {name:'shift'   , index:'shift'   , width:35, align:'right', stype:'select'                  , editable:true, edittype:"select", editoptions:{value:"0:Pilih;1:1;2:2"}, formoptions:{elmprefix:"(*)"}, formatter:'select'},
      {name:'gaji'    , index:'gaji'    , width:60, align:'right', sorttype:'int'                  , editable:true, editoptions:{size:10}, editrules:{required:true, number:true}, formoptions:{elmprefix:"(*)"}, formatter:'currency'},
      {name:'tglmasuk', index:'tglmasuk', width:50, align:'right', sorttype:'date', datefmt:'Y-m-d', editable:true, editoptions:{size:10}, editrules:{required:true, date:true}, formoptions:{elmprefix:"(*)",elmsuffix:"  dd-mm-yyyy" }},
    ],
    multiselect: true,
    altRows: true,
    pager: '#pager',
    rowNum:20,
    rownumbers: true,
    gridview: true,
    height: 300,
    autowidth: true,
    rowList:[20,50,100], <!--construct a select box element in the pager-->
    sortname: 'Id', <!--sets the initial sorting column-->
    sortorder: 'desc', <!--sets the sorting order-->
    viewrecords: true, <!--display the number of total records from the query in the pager bar.-->
    caption: 'Employee', <!--Defines the Caption layer for the grid.-->
    onSortCol: function(name,index){ alert("Column Name: "+name+" Column Index: "+index);},
    onSelectRow: function(id){ alert("You select row with id: "+id);},
    editurl:"edit.php" <!--set editUrl for add / edit/ delete operations to server.-->
  });
  jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,search:false, refresh:false, view:true},
  {jqModal:false, left: 350, drag:false, resize:false, checkOnUpdate:true, savekey: [true,13], navkeys: [true,38,40], checkOnSubmit : true, reloadAfterSubmit:true, closeOnEscape:true, bottominfo:"Isian (*) tidak boleh kosong", closeAfterEdit: true},// edit options
  {jqModal:false, left: 350, drag:false, resize:false,                     savekey: [true,13], navkeys: [true,38,40]                      , reloadAfterSubmit:true, closeOnEscape:true, bottominfo:"Isian (*) tidak boleh kosong", closeAfterAdd: true}, // add options
  {jqModal:false, left: 350, drag:false, resize:false, reloadAfterSubmit:true, closeOnEscape:true}, // del options
  {}, // search options
  {jqModal:false, left: 350, drag:false, resize:false, closeOnEscape:true}); // view options

  jQuery("#list").jqGrid('navButtonAdd',"#pager",{caption:"Clear",title:"Clear Search",buttonicon :'ui-icon-refresh', onClickButton:function(){
    mygrid[0].clearToolbar() } });
  jQuery("#list").jqGrid('filterToolbar');

});
</script>
 
</head>
<body>  <!--define where you want to place the grid-->
<table id="list"></table>
<div id="pager"></div>
</body>
</html>

Edit.php

<?
include('config/connect.php'); //connections

$id = $_POST['id']; //row id. this is the id of the selected row
$name = $_POST['name']; //some variable
$address = $_POST['address']; //some variable
$telp = $_POST['telp']; //some variable
$level = $_POST['level']; //some variable
$shift = $_POST['shift']; //some variable
$salary = $_POST['salary']; //some variable
$date = $_POST['date']; //some variable
$operation = $_POST['oper']; //can be “add” “edit” “del”

if ($operation == "edit")
{
$result = mysqli_query($link, "UPDATE employee SET name = '$name', address = '$address', telp = '$telp', level = '$level', shift = '$shift', salary = '$salary', date = '$date' WHERE id = '$id'");
}

else if ($operation == "add") {
$result = mysqli_query($link, "INSERT INTO employee(id, name, address, telp, level, shift, salary, date) VALUES ('$id', '$name', '$address', '$telp', '$level', '$shift','$salary', '$date')");
}
else if($operation == "del")
{
$result = mysqli_query($link, "UPDATE employee SET del = 2 WHERE id = '$id'");
}

mysqli_close($link);

?>

tablejson.php

<?php
//include the information needed for the connection to MySQL data base server.
// we store here username, database and password
include 'config/connections.php';
 
// to the url parameter are added 4 parameters as described in colModel
// we should get these parameters to construct the needed query
// Since we specify in the options of the grid that we will use a GET method
// we should use the appropriate command to obtain the parameters.
// In our case this is $_GET. If we specify that we want to use post
// we should use $_POST. Maybe the better way is to use $_REQUEST, which
// contain both the GET and POST variables. For more information refer to php documentation.
// Get the requested page. By default grid sets this to 1.
$page = $_REQUEST['page']; // get the requested page
 
// get how many rows we want to have into the grid - rowNum parameter in the grid
$limit = $_REQUEST['rows']; // get how many rows we want to have into the grid
 
// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel
$sidx = $_REQUEST['sidx']; // get index row - i.e. user click to sort
 
// sorting order - at first time sortorder
$sord = $_REQUEST['sord']; // get the direction
 
// if we not pass at first time index use the first column for the index or what you want
if(!$sidx) $sidx =1;

$wh = "";
$searchOn = stripslashes($_REQUEST['_search']); //a function called Strip that will remove slashes from the user typed text
if($searchOn=='true') {
    $sarr = Strip($_REQUEST);
    foreach( $sarr as $k=>$v) { //more or less this is pretty much saying for every value that the user entered in *note that the $v is data that comes out of your Strip function which as I mentioned it removes slashes from the user typed fields.
        switch ($k) {
            case 'id':
            case 'name':
            case 'address':
            case 'level':
            case 'shift':
                $wh .= " AND ".$k." LIKE '".$v."%'";
                break;
            case 'salary':
                $wh .= " AND ".$k." = ".$v;
                break;
        }
    }
}
//echo $wh;
 
// connect to the MySQL database server
//$db = mysqli_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error());
 
// select the database
//mysqli_select_db($link, $database) or die("Error connecting to db.");
switch ($examp) {
    case 1: $query = "SELECT COUNT(*) AS count FROM employee WHERE ".$wh;
            $result = $db->query($query);
            $row = $result->fetch_array(MYSQLI_ASSOC);/* associative array */
            $count = $row['count'];
 
            // calculate the total pages for the query
            if( $count >0 ) {
              $total_pages = ceil($count/$limit);
            } else {
              $total_pages = 0;
            }
 
            // if for some reasons the requested page is greater than the total
            // set the requested page to total page
            if ($page > $total_pages) $page=$total_pages;
 
            // calculate the starting position of the rows
            $start = $limit*$page - $limit;// do not put $limit*($page - 1)
            if ($startpage = $page)
            $responce->total = $total_pages;
            $responce->records = $count;
            
            $i=0;
            while($row = $result->fetch_array(MYSQLI_ASSOC)) {
                $responce->rows[$i]['id']=$row[id];
                $responce->rows[$i]['cell']=array($row[id],$row[name],$row[address],$row[telp],$row[level],$row[shift],$row[salary], $row[date]);
            $i++;
            }
        echo $json->encode($responce); // coment if php 5
        //echo json_encode($responce);
           
        break;
    case 3:
}
mysqli_close($db);

    
?>

01/02/2010
09:49
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Sorry, but we discuss here only java script and not any server side language.

You can download the demo and see how this done.

What does not work in delete? The simple test is - set:

reloadAfterSubmit to false  and see if the records are deleted from the grid.

Best Regsrds

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

02/02/2010
04:27
Avatar
Candrairawan78
Indonesia
Member
Members
Forum Posts: 39
Member Since:
30/01/2010
sp_UserOfflineSmall Offline

Dear Tony,

Thank you for your responce.

OK, I understand and appreciate your forum.

I have changed reloadAfterSubmit to false , but it only delete rows in grid, not delete data in MySQL.

Could you suggest where I can get help for my problem?

Regards,

Candra

05/02/2010
11:27
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

You will need to search this forum. There are a lot of such solutions regarding this.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
81 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information