Column with int type in kendo grid - kendo-grid

I have a Phone column in Kendo grid and its type suppose to be int.
Phone: {editable: true, type= 'number', validation: {required: true}}
When I tried to add a new record, its field is become like this
0.00
as its type is decimal, when I write number it become like this 123,345,234
I tried the following:
{field: "Phone", title:"Phone", width:"100px", format: "{0}"}
it become like this before typing on it {0}
when I wrote a number it looks like this {123345234}

Can you take a look on the pen attached and try this instead? I tried by specifying the type of the column as a number.
When a new record is added, the required field of the new record is filled with "0".
And when the number is typed, it takes a format of a number. For eg., 9876543210
Code Pen - Attached
$("#grid").kendoGrid({
columns: [
{ field: "name" },
{ field: "phone",
type:"number"
},
{ command:
{ name: "destroy" } // built-in "destroy" command
}
],
toolbar: ["save","create"],
editable: true,
dataSource: [ { name: "Jane Doe",
phone: 9876543210} ]
});
var grid = $("#grid").data("kendoGrid");
console.log(grid);
grid.addRow();
Hope this answers your question!
Happy day!!! :)

Related

How to create a typescript union type with values from a JSON object

Suppose I have this JSON object
[
{ "label": "The entire place", "value": "entire_place" },
{ "label": "A shared room", "value": "shared_room" },
{ "label": "A private room", "value": "private_room" },
]
Those represent the possible values of a dropdown menu. The label is what the user sees, and the value is what's stored in the database.
However, I also need to create a type as follows:
type Property = "entire_place" | "private_room" | "shared_room";
How can I do so without defining the data twice?
I don't want to change the type and JSON object every time I need to add a new possible values.
Any ideas how to do so? If it's not possible, what's a better alternative to store data (along their label) and use it for validation.
First, you need to declare your array as a const, that way typescript generates the specific values rather than just string. Then you can use typeof and index the array with number and lastly value:
const data = [
{ label: 'The entire place', value: 'entire_place' },
{ label: 'A shared room', value: 'shared_room' },
{ label: 'A private room', value: 'private_room' },
] as const;
type Property = typeof data[number]['value'];
Declaring it as a const does mean you can't modify the array, which is a good thing. If you want to keep it entirely in sync with the array, I don't believe that's possible.

Numeric value gets change while exporting to Excel - Dynamic Datatables

I am trying to export data as excel from dynamic data tables, but in excel the numeric value of a column gets change.
The Original Value showing in table in web application is like 1031001746692014 But upon exporting to Excel it becomes
$(document).ready(function(){
$('#tracker_list').DataTable({
dom: 'ZBflrtip',
'processing': true,
'serverSide': true,
'pageLength': 25,
'serverMethod': 'post',
'lengthMenu': [[10,25,50,100, -1], [10,25,50, 100, "All"]],
'order': [ 0, 'desc' ],
'ajax': {
'url':'ajax/url_to_method'
},
'columns': [
{ data : 'id'},
{ data: 'account_number' },
],
'columnDefs': [{
'targets': [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19], /* column index */
'orderable': true, /* true or false */
'order': [ 1, 'desc' ]
}],
//'buttons': [ 'copy', 'csv', 'excel', 'pdf', 'print' ]
});
Trying to find problem, either in datatables export mechanism or in excel ?
Found the reason.
The problem is in Excel itself. Excel cells have a limit to a specific range.
Therefore added one Apostrophe at the start of the number so it reflects in the results but in excel we can manage it by replacing it to the correct number easily.

updateSingleValue() returns false, yet inputs are correct

I'm using updateSingleValue like this:
$updated = $this->app['storage']->updateSingleValue('suggestions', $id, 'votes', $value);
The $id and $value are set correctly (even if I set them to correct integers manually), and there definitely exists a suggestions contenttype with votes field. Yet, this function returns false, suggesting that !$this->isValidColumn($field, $contenttype) fails.
A suggestion in json format looks like this:
suggestion": {
"id": "25",
"values": {
"datechanged": "2015-01-03 13:25:02",
"id": "25",
"slug": "slug-o2sbdb",
"datecreated": "2015-01-03 13:25:02",
"datepublish": "2015-01-03 13:25:02",
"datedepublish": "1900-01-01 00:00:00",
"ownerid": "1",
"status": "published",
"title": "test title",
"description": "test description",
"votes": "0"
},
The suggestion contenttype looks like this:
suggestions:
name: Suggestions
slug: suggestions
singular_name: Suggestion
singular_slug: suggestion
default_status: publish
fields:
title:
label: Title
type: text
class: large
required: true
pattern: ".{2,255}" # see: http://html5pattern.com/
error: "The Title field is required, and must contain at least 2 characters"
description:
label: Description
type: textarea
votes:
label: Votes
type: integer
What can I be doing wrong here?
Found the problem here the contenttype passed into updateSingleValue needs to be the entire contenttype not just the slug 'suggestions'. You can fetch it via the storage class method:
$app['storage']->getContentType('suggestions')
then pass in the result of that to the updateSingleValue method.

How to list object key names with jsonpath?

I am using nodejs with jsonpath.
I have this json structure:
{
things:{
books: [
{name: "book1"},
{name: "book2"},
{name: "book3"},
{name: "book4"},
],
movies: [
{name: "movie1"},
{name: "movie2"},
{name: "movie3"},
{name: "movie4"},
]
}
}
I would like to know the jsonpath expression that returns an array with the key names of the things object. That would be:
["books","movies"]
For now, I am doing this:
Object.keys(jsonpath.eval(jsonStructure,"$.things").pop());
But I don't find it elegant... I should not need to get a copy the whole structure when I only need the key names.
jsonPath has new update jsonpath-plus
jsonpath-plus expands on the original specification to add some additional operators and makes explicit some behaviors the original did not spell out.
^ for grabbing the parent of a matching item
~ for grabbing property names of matching items (as array)
so to get proper output use this query things.*~
you can try here also https://jsonpath.com/
I don't believe there is a better solution than your own:
Object.keys(jsonpath.eval(jsonStructure,"$.things").pop());
I think the main misconception here is that you don't have to worry about this snippet "getting a copy of the whole structure", because you aren't copying the whole structure. You already have the entire object loaded into memory, jsonpath doesn't create a new copy, it simply returns a reference to the already existing object, i.e.:
jsonpath.eval(jsonStructure,"$.things").pop() === jsonStructure.things //true
Not exactly what you are asking for, but might still be relevant.
We use object-scan for this kind of task as it is much better suited for data processing and analyzing. Once you wrap your head around it that is (:
Anyways, here is how you could answer your question if you are willing to add another dependency
// const objectScan = require('object-scan');
const data = { things: { books: [ { name: 'book1' }, { name: 'book2' }, { name: 'book3' }, { name: 'book4' } ], movies: [ { name: 'movie1' }, { name: 'movie2' }, { name: 'movie3' }, { name: 'movie4' } ] } };
console.log(objectScan(['things.*'], { rtn: 'property' })(data));
// => [ 'movies', 'books' ]
.as-console-wrapper {max-height: 100% !important; top: 0}
<script src="https://bundle.run/object-scan#13.7.1"></script>
Disclaimer: I'm the author of object-scan
The syntax you used for give is wrong
to get keys in json path use "$.*~"
ex.
input:
{
"firstName": "John",
"lastName" : "doe",
"age" : 26
}
output:
[
"firstName",
"lastName",
"age"
]

Mapping JSON data in JQGrid

I am using jqGrid 3.6.4 and a jquery 1.4.2 . in my sample i am getting following json data format & i want to map these json data into rows of a jqgrid
{
"page": "1",
"total": 1,
"records": "6",
"rows": [
{
"head": {
"student_name": "Mr S. Jack ",
"year": 2007
},
"sub": [
{
"course_description": "Math ",
"date": "22-04-2010",
"number": 1,
"time_of_add": "2:00",
"day": "today"
}
]
}
]
}
my jqgrid code is as follows
jQuery("#"+subgrid_table_id).jqGrid({
url:"http://localhost/stud/beta/web/GetStud.php?sid="+sid,
dtatype: "json",
colNames: ['Stud Name','Year','Date'.'Number'],
colModel: [ {name:'Stud Name',index:'student_name', width:100, jsonmap:"student_name"},
{name:'Year',index:'year', width:100, jsonmap:"year"},
{name:'Date',index:'date', width:100, jsonmap:"date"},
{name:'Number',index:'number', width:100, jsonmap:"number"}
],
height:'100%',
jsonReader: { repeatitems : false, root:"head" },
});
So now the problem is as my data i.e. student_name and year is under "head" , the jqgrid is enable to locate these two fields. at the same time other two column values i.e. Date and Number lies under "sub" and even those columns i am not be able to map it with jqgrid
so kindly help me how to located these attributes in JQGrid.
Thanks
First of all the code posted has some errors like dtatype: "json" instead of datatype: "json". "},});" instead of "}});" at the end of code and colNames: ['Stud Name','Year','Date'.'Number'] instead of colNames: ['Stud Name','Year','Date','Number']. After fixing this clear bugs you need change jsonmap values. This was your main question. The fixed code will be look like following:
jQuery("#"+subgrid_table_id).jqGrid({
...
datatype: 'json',
colNames: ['Stud Name','Year','Date'.'Number'],
colModel: [
{name:'student_name', width:100, jsonmap:"head.student_name"},
{name:'year', width:100, jsonmap:"head.year"},
{name:'date', width:100, jsonmap:"sub.0.date"},
{name:'number', width:100, jsonmap:"sub.0.number"}
],
jsonReader: { repeatitems:false, root:"rows" }
});
You have to fix root to "rows" and use jsonmap in JSON dot notation (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_dot_notation). I use a little strange notation like "sub.0.number" because sub.0.number in JavaScript is the same as sub[0].number. It works now.
I recommend you think one more about the structure of JSON data which you receive. (see my previous comments to you question): Is "sub" element is really an array with always one element or you want to use subgrids? Probably the data should be changed from sub:[{"":"", ...}] to sub:{"":"", ...}? What do you want to use as a rowid? student_name? Then add id: "head.student_name" to the jsonReader definition or add key: true property to the definition of the column student_name. Or you forget to include it in the JSON data?
And the last suggestion. If you open http://trirand.com/blog/jqgrid/jqgrid.html and opens on the left side of tree the branch "Data Mapping" \ "Data optimization" you will see an example where on use only array instead of named elements in JSON. Such data will be have minimum size and can be transferred more quickly from server to client. You data instead have some fields (like "course_description") which you don't use at all. So if you can make any changes in the server code try to optimize the data transfer rate.