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
jqgrid cascading dropdown
18/02/2013
12:42
Avatar
leerickx
brussels
Member
Members
Forum Posts: 9
Member Since:
18/02/2013
sp_UserOfflineSmall Offline

Hello everybody… i'm lost  ,

I try to realize cascading dropdown. My data is in tables.

If i choose an item in the first ddl the second ddl change right.

But the first time that i want edit or add my second ddl present all items from the table (ddlprojet – table :projet).

How I can do change this ? Thanks for all.

My html code:

<!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>My First Grid</title>

<link rel="stylesheet" type="text/css" media="screen" href="css/redmond/jquery-ui-1.10.0.custom.min.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 src="js/jquery-1.9.0.min.js" type="text/javascript"></script>

<script src="js/i18n/grid.locale-fr.js" type="text/javascript"></script>

<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>

<script>

$(function(){

  $("#list").jqGrid({

    //=============

    // Grid Setup

    url:'example.php',

    datatype: 'xml',

    mtype: 'GET',

    pager: '#gridpager',

    width: 700,

    height: '130%',

    rowNum:10,

    rowList:[10,20,30],

    sortname: 'secteur',

    sortorder: 'desc',

    viewrecords: true,

    gridview: true,

    editurl: "addupdatedeldata.php",

    onSelectRow: function(rowid) {

                    if (rowid != null) {

                        var record = $("#list").getRowData(rowid);

                        var pgm="ddlprojet.php?id_secteur="+record.idsecteur;

                        $("#list").setColProp('select#idprojet',{editoptions:{dataUrl:pgm}});

                        }

                    },

    caption: 'FICHE PROJET',

    // Column definition

    colNames:['id','date', 'secteur','projet'],

    colModel :[

      {name:'id', index:'id', width:55},

      {name:'date', index:'date', width:90, editable:true},

      {name:'idsecteur', index:'idsecteur', width:80, align:'right', editable:true, edittype:"select", 

        editoptions:{dataUrl:'ddlsecteur.php', dataEvents:[{type: 'change',

                                                        fn: function(e) {var thisval = $(e.target).val();

                                                                            $.get('ddlprojet.php?id_secteur='+thisval,

                                                                            function(data)

                                                                            { $("select#idprojet").html(data);

                                                                            }); // end get

                                                                        }//end func

                                                        } // end type

                                                      ] // dataevents

                    } // edit option

    },

      {name:'idprojet', index:'idprojet', width:80, align:'right', editable:true, edittype:"select", editoptions:{dataUrl:'ddlprojet.php?id_secteur=idsecteur'}}

    ]

      });

    //=============

    // NavGrid Setup

    $("#list").jqGrid('navGrid','#gridpager',

    {edit:true,

    add:true,

    del:true,

    search:true},  

    {viewPagerButtons:false,

    recreateForm:true

    //refresh:true

    });

});

</script>

</head>

<body>

<table id="list"><tr><td/></tr></table>

<div></div>

</body>

</html>

my ddlsecteur.php

<?php

    include("dbconfig.php");

    $sql = "SELECT * FROM secteur";

    echo '<select>';

    $result = mysql_query($sql) or die("Couldn't execute query.".mysql_error());

    while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {

         echo '<option value="'.$row['idsecteur'].'">'.$row['secteur'].'</option>';

    }

    echo '</select>';

//mysql_close($db); 

?>

my ddlprojet.php

<?php

    include("dbconfig.php");

    if(isset($_GET['id_secteur'])){

    $id_secteur=$_GET['id_secteur'];

    $sql="select idprojet, projet, idsecteur from projet where idsecteur=$id_secteur";   

    }

    else {

    $sql="select projet.idprojet, projet.projet from projet inner join secteur on secteur.idsecteur=projet.idsecteur where secteur.secteur='$id_secteur'";   

    //$sql="select idprojet, projet, idsecteur from projet where idsecteur=$id_secteur";   

    }   

    $rs = mysql_query($sql);

    echo "<select>"; 

    while ($reg=mysql_fetch_array($rs)) {

    echo "<option value='".$reg['idprojet']."'>".$reg['projet']."</option>";

    }

    echo"</select>";

    mysql_close($db);

?>

well I see that I'm missing something but I do not see.

I can display secteur in my first dll within dataUrl but I've proble when I edit a row, the select secteur is no good.

function loadsecteur(){var sect = null;$.get("ddlsecteur.php", function(data){sect = data;  $('#idsecteur').html(sect);}});      

{name:'idsecteur', index:'idsecteur', width:80, align:'right', editable:true, edittype:"select",

                              editoptions:{value:loadsecteur, 

 dataEvents:[{type: 'change', fn: function(e) {var thisval = $(e.target).val(); 

 $.get('ddlprojet.php?id_secteur='+thisval, function(data){ $("select#idprojet").html(data); 

}); // end get }// end func} // end type ] // dataevents }// edit option},

but how not display in the ddlprojet all item of my table projet

Should I change and add a function there ?

$("#ficheprojet").jqGrid('navGrid','#gridpager',{edit:true,add:true,del:true,search:true},    {//prmEdit    closeAfterEdit:true, viewPagerButtons:false,    recreateForm:true //refresh:true    }, {//prmAdd closeAfterAdd:true    }

thanks for all.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
28 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