<div id="Grid" ej-grid e-datasource="data">
in above code all information to form a grid passing through
$scope.data = dataforgrid;
<div id="grid" ej-grid e-datasource="data" e-create="create"></div> angular.module('GridCtrl', ['ejangular']) .controller('Grid', function ($scope) { $scope.data = obj; $scope.create = function (args) { var gridobj = $("#grid").ejGrid("instance"); for (i = 0; i < args.model.columns.length; i++) { args.model.columns[i].width = 130; if (args.model.columns[i].type == "number" || args.model.columns[i].type == "date") { args.model.columns[i].textAlign = "right"; args.model.columns[i].width = 50; if(args.model.columns[i].type == "date") args.model.columns[i].format = "{0:MM/dd/yyyy}"; } } gridobj.columns(args.model.columns); }
|
Hi Gomtesh,
We have analyzed your requirement to dynamically set the alignment, width and format to the columns.
Thus we have created a sample based on the above requirement and the sample can be downloaded from the below location.
Sample Link: http://www.syncfusion.com/downloads/support/forum/119343/ze/AngularJS-579542244
In the above sample, we have set the alignment, width of the columns in the create event of the event and have passed the modified columns to the columns() method of the grid. Please refer the below code snippet.
<div id="grid" ej-grid e-datasource="data" e-create="create"></div>
angular.module('GridCtrl', ['ejangular'])
.controller('Grid', function ($scope) {
$scope.data = obj;
$scope.create = function (args) {
var gridobj = $("#grid").ejGrid("instance");
for (i = 0; i < args.model.columns.length; i++)
{
args.model.columns[i].width = 130;
if (args.model.columns[i].type == "number" || args.model.columns[i].type == "date") {
args.model.columns[i].textAlign = "right";
args.model.columns[i].width = 50;
if(args.model.columns[i].type == "date")
args.model.columns[i].format = "{0:MM/dd/yyyy}";
}
}
gridobj.columns(args.model.columns);
}
});
Please try the sample and get back to us if you need any further assistance.
Regards
Ragavee U S
Hi Gomtesh,
We have analyzed your requirement to dynamically set the alignment, width and format to the columns.
Thus we have created a sample based on the above requirement and the sample can be downloaded from the below location.
Sample Link: http://www.syncfusion.com/downloads/support/forum/119343/ze/AngularJS-579542244
In the above sample, we have set the alignment, width of the columns in the create event of the event and have passed the modified columns to the columns() method of the grid. Please refer the below code snippet.
<div id="grid" ej-grid e-datasource="data" e-create="create"></div>
angular.module('GridCtrl', ['ejangular'])
.controller('Grid', function ($scope) {
$scope.data = obj;
$scope.create = function (args) {
var gridobj = $("#grid").ejGrid("instance");
for (i = 0; i < args.model.columns.length; i++)
{
args.model.columns[i].width = 130;
if (args.model.columns[i].type == "number" || args.model.columns[i].type == "date") {
args.model.columns[i].textAlign = "right";
args.model.columns[i].width = 50;
if(args.model.columns[i].type == "date")
args.model.columns[i].format = "{0:MM/dd/yyyy}";
}
}
gridobj.columns(args.model.columns);
}
});
Please try the sample and get back to us if you need any further assistance.
Regards
Ragavee U SHi...As you given solutiongridobj.columns(args.model.columns);but in gridobj. columns property is not presentAlso i have to add columns into gridFor that i have written :: args.model.columns.push(columnName);but its not working so how can i add column dynamically
$scope.dataBound = function (args) { . . . . . var userfields = data; var gridObj = $("#Grid").data("ejGrid"); gridObj.model.columns = []; for (var i = 0; i < userfields.length; i++) { . . . . gridObj.columns(userfields[i].FieldName); } |
var gridobj = $("#Editing").data("ejGrid"); var col = gridobj.getColumnByHeaderText("Freight"); //get the JSON object of the column corresponding to the headerText col.headerText = "Changed Text"; // assign a new header text to the column gridobj.columns(col); //pass the updated column object to the columns method |