select2 and autofilter

Questionsselect2 and autofilter
Sergio Pulido asked 10 years ago

hello mi file actual is jqgrid_dist of 164 kb, I have problem for select2, no inicialice, and firebug, no errors. What happened?. my code:
$col = array();
$col["title"] = "Cliente";
$col["name"] = "IdCliente";
// this is required as we need to search in name field, not id

$col["dbname"] = "ha_clientes.IdCliente";
$col["width"] = "120";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select"; // render as select

$str = $grid->get_dropdown_values("select distinct IdCliente as k, Nombre as v from ha_clientes");
$col["editoptions"] = array("value"=>$str);

$col["editoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_select2('{$col["IdCliente"]}'); },200); }";

$col["stype"] = "select"; // render as select
$col["searchoptions"] = array("value"=>$str);
$col["searchoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_select2('gs_{$col["IdCliente"]}'); },200); }";
$cols[] = $col;
… too copy style,of demo and add my page.
In body page:
<script>
function link_select2(id)
{
$('select[name='+id+'].editable, select[id='+id+']').select2({width:'95%', dropdownCssClass: 'ui-widget ui-jqdialog'});
$(document).unbind('keypress').unbind('keydown');
}
</script>

5 Answers
Abu Ghufran answered 10 years ago

Please make sure you include the select2 JS files.

<link rel="stylesheet" href="//cdn.jsdelivr.net/select2/3.5.2/select2.css">
<script src="//cdn.jsdelivr.net/select2/3.5.2/select2.min.js"></script>

Code: http://phpgrid.org/demo/demos/integrations/dropdown-select2.phps

Sergio Pulido answered 10 years ago

works ok, but I happen to have a second, "select" because it is a page "detall master" and the second "select" not let me write.
I use Firefox, and at the bottom I get "javascript: void (0)"; when I try to make changes.
Thanks, Sergio Pulid0

Abu Ghufran answered 10 years ago

In your code,

$col["editoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_select2('{$col["IdCliente"]}'); },200); }";

the var: $col["IdCliente"] – should be: $col["name"]. e.g.

$col["editoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_select2('{$col["name"]}'); },200); }";

The variable is $col["IdCliente"] is not defined and may be causing conflict. By setting $col["name"], the select2 will always have different id.

Wa Wa answered 6 years ago

$col[“edittype”] = “select”; // render as select
$col[“editoptions”] = array(“value”=>”:;”.$str);
$col[“editoptions”][“dataInit”] = “function(){ setTimeout(function(){ link_select2(‘{$col[“name”]}’); },200); }”;

why the resultant drop down option does not contain a blank option although this is supplied? array(“value”=>”:;”.$str);

Abu Ghufran Staff answered 6 years ago

When using select2, you must pass some label in order to have blank value.

Try this:
$col[“editoptions”] = array(“value”=>”:-;”.$str);

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

8 + 3 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?