Adding dynamic column header to ng grid - ng-grid

Hi I want to add some columns dynamically (fetching from server) to the already populated column header,I am able to see the static column but the dynamic column are not updated , but I generate the gridoptions.columndef such that the dynamic columns are appended to it,but,in view its not reflecting.
plunker

Here is a plunker that shows how you can do it:
http://plnkr.co/edit/Ko0H8ZltkpngGodaB936?p=preview
$scope.colDefs1 = [{field: 'name', displayName: 'Name'}, {field:'age', displayName:'Age'}];
$scope.colDefs2 = [{field: 'name', displayName: 'Name'}, {field:'age', displayName:'Age'}, {field:'occupation', displayName:'Occupation'}];
$scope.gridOptions = {
data: 'myData',
columnDefs: 'colDefs1'
};
$scope.addColumns = function(){
$scope.colDefs1 = $scope.colDefs2;
}
See also this link to explain why I did it this way:
https://github.com/angular-ui/ng-grid/issues/128
Update: Here is your plunker with todos.json converted to valid JSON and working:
http://plnkr.co/edit/0eRwaBaOv7xaZbMHvbiR?p=preview

Related

Does not contain a definition for 'file_src' October CMS

I am currently working at October CMS plugin development, I have a problem with file upload. I put the fileupload type to file_src. When I go to to resource it shows an error like this :
model/resource
fields:
name:
label: Name
type: text
required: true
file_src:
label: Upload
type: fileupload
grade_id:
label: Grade
type: dropdown
emptyOption: Select
showSearch: true
subject_id:
label: Subject
type: dropdown
emptyOption: Select
showSearch: true
type_id:
label: Type
type: dropdown
emptyOption: Select
showSearch: true
How can I fix this error?
I fixed it! We must use $attachOne or $attachMany relation on model
I added following code in Resource.php in models
public $attachOne = [
'file_src' => 'System\Models\File'
];
thats it its working now!
Define the current module the selected control is a file. Mean your
current selected control is as a file and you does not define in your
module that time the backend has confused.
Solution:
public $attachOne = [
'profile_pic' => \System\Models\File::class
];

How can i bind an json data with a key and Name for display

I have a situation to bind a json data with a key to plot a graph. But graph is plotting correctly but the name of the data is showing the same key. i need to avoid it .
How can i supply a name for my data. I have tried as follows but its seems not working.
Can any guys help one this.
data: {
// columns: [chartData],
json: data,
keys: {
value: [key]
},
type: chartType,
labels: true,
selection: {
enabled: false
},
names: {
data1: 'Some Name'
}
}
Thanks in Advance :)
Kiran Gopal
Instead of data1, you should substitute the value of the variable key. Or you could construct the names value, like so
var names = {}
names[key] = 'Some Name';
var chart = c3.generate({
...
names: names
},
});
Fiddle - http://jsfiddle.net/Ld2apq0g/

Sorting a Column by Default (on load) Using Dojo Dgrid

When loading a dgrid from a dojo store, is there a way to specify a column to be sorted by default.
Say I have 2 columns, Name and Email, I want the name column sorted by default when the grid is first loaded. What I want is the equivalent of the user clicking on the 'Name' header (complete with the sort arrow indicating the sort direction).
Thanks,
John
You can do something like this :
var mygrid = new OnDemandGrid({
store : someStore,
queryOptions: {
sort: [{ attribute: "name" }]
}
// rest of your grid properties
}, "someNode");
dgrid 1.1.0 - set initial/default sort order
var TrackableRest = declare([Rest, SimpleQuery, Trackable]);
var store = new TrackableRest({target: apiUrl, useRangeHeaders: true, idProperty: 'id'});
var grid = new (declare([OnDemandGrid, Selection, Editor]))({
collection: store,
sort: [{"property":"name", "descending": false}],
className: "dgrid-autoheight",
columns: {
id: {
label: core.id
},
category_text: {
label: asset.category
},
name: {
label: asset.model,
},

jqgrid editable x number formating is inconsisent with format on grid

I've built a grid as the code bellow:
colModel: [
{ name: 'price',
label: 'price',
index: 'price',
jsonmap: 'price',
formatter: 'number',
formatoptions: {decimalSeparator:",", thousandsSeparator: ".", decimalPlaces: 2, defaultValue: '0,00'},
editable: true
}
]
The format of field is correctly on grid, for instance: 10,32, but the form created to edit the field fills one with 10.32 instead of 10,32.
Someone knows why this is going on? Do I need to use properties as edittype and editoptions (this one using formmater and formatoptions) as well? if yes, How I need set up these properties?
I've fixed the problem using the the function afterShowForm to handle the formating of field on form generated from grid.
In fact, I was expecting that jQGrid could do that automatically, i.e, using the configuration provided to column to apply on field generated, or if i could apply the configurion on JSON message, for instance:
editoptons: { formatter = "number", formatteroptions = { .... } ...
anyway, it's working now.

mixed sorting in extjs grid

I want to sort a column based on text and numbers.
values i have are sorted like this:
- List:010
- List:100
- List:134
- List:2
- List:204
but what i need is
- List:2
- List:010
- List:100
- List:134
- List:204
the column type i am using is string. i tried to use sortType but that was not working.
{
name: 'listItems',
type: 'string',
mapping: 'listItems'
}
If you are using ExtJS 4.x, you can take advantage of the SortTypes class.
Ext.apply(Ext.data.SortTypes, {
asPerson: function(person){
// expects an object with a first and last name property
return person.lastName.toUpperCase() + person.firstName.toLowerCase();
}
});
Ext.define('Employee', {
extend: 'Ext.data.Model',
fields: [{
name: 'person',
sortType: 'asPerson'
}]
});
More information on the SortTypes doc page.

Resources