jQuery UI Widgets › Forums › Grid › Problem color head json
This topic contains 2 replies, has 2 voices, and was last updated by nostromo 6 years ago.
-
AuthorProblem color head json Posts
-
Dear, I have a simple grid to which I change the color of the second column header. All good when I read the data from an arrangement.
The problem is that when I change the array data source to json, the color change in the header column does not work anymore.
Any idea of what can happen?Code OK with arrangement!
var data = generatedata(50);
var source = {
localdata: data,
datafields: [
{name: ‘firstname’, type: ‘string’},
{name: ‘lastname’, type: ‘string’}],
datatype: “array”
};
var dataAdapter = new $.jqx.dataAdapter(source);
$(“#grid”).jqxGrid(
{
source: dataAdapter,
width: 500,
columns: [
{ text: ‘FirstName’, dataField: ‘firstname’, width: 80, align: ‘center’, cellsalign: ‘center’ },
{ text: ‘LastName’, dataField: ‘lastname’, width: 90, align: ‘center’, cellsalign: ‘center’ }
]
}
);var firstNameCell = $(‘div .jqx-grid-column-header:eq(1)’);
firstNameCell.css(‘background-color’, ‘rosybrown’);
});
</script>
</head>
<body>
<div id=”grid”></div>
</body>
</html>
code using json, the second column color change header no longer worksvar data = generatedata(50);
var source = {
url: “qry_datosGrilla.cfm”,
datafields: [
{name: ‘firstname’, type: ‘string’},
{name: ‘lastname’, type: ‘string’}],
datatype: “json”
};
var dataAdapter = new $.jqx.dataAdapter(source);
$(“#grid”).jqxGrid(
{
source: dataAdapter,
width: 500,
columns: [
{ text: ‘FirstName’, dataField: ‘firstname’, width: 80, align: ‘center’, cellsalign: ‘center’ },
{ text: ‘LastName’, dataField: ‘lastname’, width: 90, align: ‘center’, cellsalign: ‘center’ }
]
}
);var firstNameCell = $(‘div .jqx-grid-column-header:eq(1)’);
firstNameCell.css(‘background-color’, ‘rosybrown’);
});
</script>
</head>
<body>
<div id=”grid”></div>
</body>
</html>Hello nostromo,
This happens because when you use url in the source, instead of localdata,
your code for applying css to the header cell is executed before the grid is rendered.
To fix this, move the code in theready
callback of the grid:$("#grid").jqxGrid( { source: dataAdapter, width: 500, ready: function () { let firstNameCell = $('.jqx-grid-column-header:eq(1)'); firstNameCell.css('background-color', 'rosybrown'); }, columns: [ { text: 'FirstName', dataField: 'firstname', width: 80, align: 'center', cellsalign: 'center' }, { text: 'LastName', dataField: 'lastname', width: 90, align: 'center', cellsalign: 'center' } ] } );
Best Regards,
MartinjQWidgets Team
http://www.jqwidgets.com/Excellent!!!
-
AuthorPosts
You must be logged in to reply to this topic.