1
jQgridによって生成されたテキストボックスのオートコンプリートを実装しようとしていました。 PhpページはJSONデータを返します。ここで私はこれまで行うことができたものです。(助けてください)phpページから返されたJSONデータでjQgridのオートコンプリート
function autocomplete_element(value, options) {
var $ac = $('<input type="text"/>');
$ac.val(value);
$ac.autocomplete({
source: function(request, response) {
$.getJSON("autocomplete.php", { q: request.term }, response);
}
});
return $ac;
}
function autocomplete_value(elem, op, value) {
if (op == "set") {
$(elem).val(value);
}
return $(elem).val();
}
$(function(){
$("#list").jqGrid({
url:'process1.php',
datatype: 'xml',
mtype: 'GET',
colNames:['Column Name'],
colModel :[
{name:'columnid', index:'columnid', width:50, edittype:'custom',
editoptions: {
custom_element : autocomplete_element,
custom_value : autocomplete_value
}
}
]
........
........
////////////////////////////////////////////////
/// THE PHP PAGE ////
////////////////////////////////////////////////
/*
autocomplete.php
*/
<?php
require_once("../dbconfig.php");
$term = trim(strip_tags($_REQUEST['q']));//retrieve the search term that autocomplete sends
$qstring = "SELECT description as value, id FROM test WHERE name LIKE '%".$term."%'";
$result = mysql_query($qstring);//query the database for entries containing the term
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))//loop through the retrieved values
{
$row['id']=(int)$row['id'];
$row['value']=htmlentities(stripslashes($row['value']));
$row_set[] = $row;//build an array
}
echo json_encode($row_set);//format the array into json data
?>
私は、このような$ ac.autocompleteのソースで[「何とか」、「こんにちは」、「こんにちは」]などのデータを使用し、事うまく動作するようです。しかし、私は約2000行のデータを検索する必要があります。 jQgridフォームが正しく動作しており、&編集データを追加できるようになりました。また、私はブラウザを指すときに適切なJSONデータを表示するPHPページをテストしました。私はjQueryにあまり慣れていないので、PHPページから返されたデータでオートコンプリートを打つだけです。助けてください。