Excel view: modify a value cell by a value of previous cell and how display any errors

QuestionsExcel view: modify a value cell by a value of previous cell and how display any errors
Massimo Gagliardi asked 8 years ago

Hi Abu.
I changed a my grid from normal mode to excel view mode.
Now I have 2 problems.
Point one:
Previously I calculated the value of a column on basis of the value of the previous column.
If I use this slice code:

$col = array();
$col["title"] = $GLOBALS['language']['cost'];
$col["name"] = "Costo";
$col["width"] = "12";
$col["align"] = "right";
$col["hidden"] = (strpos($columns, ',' . $col["name"] . ',') > -1)?true:false;
$col["editable"] = true;
$col["editrules"] = array("custom"=>true, "custom_func"=>"function(val, label){return validaNumber(val, label);}");
$col["editoptions"] = array("size"=>$col["width"], "style"=>"text-align: right;");
$col["editoptions"]["onchange"] = "setPrezzoIntermedio(this)";
$col["formatter"] = "currency";
$col["formatoptions"] = array("prefix"=>"€ ",
"thousandsSeparator" => $GLOBALS['language']['thousandsSeparator'],
"decimalSeparator" => $GLOBALS['language']['decimalSeparator'],
"decimalPlaces" => 2);
$col["export"] = (strpos($columns, ',' . $col["name"] . ',') > -1)?false:true;
$cols[] = $col;

$col = array();
$col["title"] = $GLOBALS['language']['intermediate price'];
$col["name"] = "PrezzoIntermedio";
$col["width"] = "12";
$col["hidden"] = (strpos($columns, ',' . $col["name"] . ',') > -1)?true:false;
$col["align"] = "right";
$col["editable"] = true;
$col["editrules"] = array("custom"=>true, "custom_func"=>"function(val, label){return validaNumber(val, label);}");
$col["editoptions"] = array("size"=>$col["width"], "style"=>"text-align: right;");
$col["formatter"] = "currency";
$col["formatoptions"] = array("prefix"=>"€ ",
"thousandsSeparator" => $GLOBALS['language']['thousandsSeparator'],
"decimalSeparator" => $GLOBALS['language']['decimalSeparator'],
"decimalPlaces" => 2);
$col["export"] = (strpos($columns, ',' . $col["name"] . ',') > -1)?false:true;
$cols[] = $col;

…….

<script language="javascript" type="text/javascript">
var valuta = '€ ';
function setPrezzoIntermedio(o) {
var grid = $("#list1");
var selr = grid.jqGrid("getGridParam","selrow");
var v = o.value;
v = v.replace('.',',');
v = valuta + v;
$("#"+selr+" td[aria-describedby='list1_PrezzoIntermedio']").text(v);
$("#"+selr+" td[aria-describedby='list1_PrezzoIntermedio']").attr("title", v);
$("#"+selr+" td[aria-describedby='list1_PrezzoIntermedio']").removeClass("edit-cell ui-state-highlight");
$("#"+selr+" td[aria-describedby='list1_PrezzoIntermedio']").addClass("dirty-cell");
$("#"+selr+" td[aria-describedby='list1_PrezzoIntermedio']").attr("tabindex","-1");
}
</script>

It get that the next cell is updated but the entire grid is no longer active, as had lost the focus.
Point two:
If I must display an error, using pgpgrid_error, I obtain an server error and not my alert.
Suggestions.
Thanks in advance
Massimo Gagliardi

4 Answers
Massimo answered 8 years ago

Hi Abu,
I don't know if is the best solution but I solved put a custom function, in witch I calculate the next cell and verify any error, in:

$col["editrules"] = array("custom"=>true, "custom_func"=>"function(val, label, x){return validaCellNumber(val, label, 3);}");

I'm waiting your remark.
thk

Abu Ghufran answered 8 years ago

Yes, this should work fine.
For 500 error code message, currently alternate method is not supported.

Massimo answered 8 years ago

Hi Abu,
I found a bug.
When the user put into a cell a numeric value with italian format using decimals with , separator the value disappears; this happens also if I correct the comma in point via custom_func.
How can I do?
Thanks in advance

Abu Ghufran answered 8 years ago

If i understand issue correct,

If your database field is numeric, then your input should not have comma.
In database numeric values can be 0-9 and decimal.

If you change the database field to varchar, then comma as input is storable.

Your Answer

14 + 11 =

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?