jqGrid the correct way to expand column width - asp.net-mvc

I am attempting to widen my columns here with the colModel property of jqGrid. when I do this, my table data disappears. Does any body know why this would happen. Before and after pictures will be below. As well as the jquery code that I use.
Here is an example of it working.
Here is an example after I have attempted to widen the columns
jQuery(document).ready(function () {
ShowMessage();
tableToGrid("#table1", {
height: '200',
shrinkToFit: false,
autowidth: true,
colNames: ['Edit',
'MRN',
'Hospital Fin',
'First Name',
'Last Name',
'Date of birth',
'Completed Pathway',
'Completed Pathway Reason',
'PCP Appointment',
'Specialist Appointment',
'Admit Date',
'Discharge Date',
'Discharge Disposition',
'Discharge To',
'Discharge Advocate Call',
'Home Healthcare',
'Safe Landing Accepted',
'PCP Name',
'PCP Phone',
'PCP Appointment Location',
'Specialist Name',
'Specialist Phone',
'Specialist Appointment Location',
'Comments',
'Patient Room',
'Phone',
'Payor',
'MRN Type'
],
colModel: [{ name: 'Edit', width: 55 },
{ name: 'MRN', width: 55 },
{ name: 'HospitalFin', width: 85 },
{ name: 'FirstName', width: 85 },
{ name: 'LastName', width: 85 },
{ name: 'Dateofbirth', width: 85 },
{ name: 'CompletedPathway', width: 145 },
{ name: 'CompletedPathwayReason', width: 165 },
{ name: 'PCPAppointment', width: 145 },
{ name: 'SpecialistAppointment', width: 165 },
{ name: 'AdmitDate', width: 55 },
{ name: 'DischargeDate', width: 80 },
{ name: 'DischargeDisposition', width: 180 },
{ name: 'DischargeTo', width: 55 },
{ name: 'DischargeAdvocateCall', width: 165 },
{ name: 'HomeHealthCareAccepted', width: 165 },
{ name: 'SafeLandingAccepted', width: 165 },
{ name: 'PCPName', width: 55 },
{ name: 'PCPPhone', width: 55 },
{ name: 'PCPAppointmentLocation', width: 165 },
{ name: 'SpecialistName', width: 185 },
{ name: 'SpecialistPhone', width: 185 },
{ name: 'SpecialistAppointmentLocation', width: 185 },
{ name: 'Comments', width: 55 },
{ name: 'PatientRoom', width: 85 },
{ name: 'Phone', width: 85 },
{ name: 'Payor', width: 85 },
{ name: 'MRNType', width: 85 }
]
});
$(window).bind('resize', function () {
$("#table1").fluidGrid({ example: "#tempplateInfo", offset: -10 });
$("#table1 tbody").sortable("destroy");
});
(function ($) {
jQuery.jgrid.fluid = {
fluidGrid: function (options) {
var grid = $(this);
var settings = $.extend({
example: grid.closest('.ui-jqgrid').parent(), offset: 0
},
options || {});
var width = $(settings.example).innerWidth() + settings.offset; grid.setGridWidth(width);
}
}
})
(jQuery);
jQuery.fn.extend({ fluidGrid: jQuery.jgrid.fluid.fluidGrid });
var $grid = $('#table1'),
hdiv = $grid[0].grid.hDiv,
$columnHeaders = $("thead tr.ui-jqgrid-labels th", hdiv)
$columnHeaders.unbind('mouseenter');
$columnHeaders.unbind('mouseleave');
Comment out the columnModel section to get an idea of what I had when it was working. Should the colModel name property be equal to the th for instance? What is the word good fellows. I am getting inconsitent results.

Related

Treetable with horizontal scrollbar

Codepen example
Here's a codepen demonstrating a treetable with groups:
https://codepen.io/dharmatech/full/mdWGbox
Screenshot
Screenshot of the above treetable:
The Issue
Only some of the columns are shown; there are many more available. However, note that there is no horizontal scrollbar shown at the bottom to bring the other columns into view.
Is there a way to turn on a horizontal scrollbar?
Approaches I've explored
I've tried each of these:
scrollX: true,
scroll: 'xy',
However, they don't seem to enable a scrollbar.
Treetable Code
Code for the treetable demonstrated above:
{
view: "treetable",
id: "grida",
columns: [
//{ id: "Id", },
//{ id: "Date" },
{
id: "Date",
header: 'Food',
width: 300,
template: function (obj, common) {
if (obj.value) {
return common.treetable(obj, common) + obj.value + `<button onclick=' ( function() { console.log( "${obj.value} - ${obj.Date} - ${obj.Time}" ); } )(); '>Add</button>`;
}
else {
return common.treetable(obj, common) + obj.Food;
}
}
},
// { id: "Time" },
// { id: "Food" },
{ id: "Amount", header: 'Amt', width: 50 },
{ id: "Calories", header: "Cal", width: 50 },
{ id: "Fat", header: "Fat", width: 50 },
{ id: "MonounsaturatedFat", header: "Mono", width: 50 },
{ id: "PolyunsaturatedFat", header: "Poly", width: 50 },
{ id: "Omega3", header: "Om3", width: 50 },
{ id: "Omega6", header: "Om6", width: 50 },
{ id: "SaturatedFat", header: "Sat", width: 50 },
{ id: "TransFat", header: "Trans", width: 50 },
{ id: "Cholesterol", header: "Chole", width: 50 },
{ id: "Carbohydrates", header: "Carb", width: 50 },
{ id: "Fiber", header: "Fib", width: 50 },
{ id: "SolubleFiber", header: "Sol", width: 50 },
{ id: "InsolubleFiber", header: "Ins", width: 50 },
{ id: "Starch", header: "Star", width: 50 },
{ id: "Sugars", header: "Sug", width: 50 },
{ id: "AddedSugars", header: "Add", width: 50 },
{ id: "Protein", header: "Pro", width: 50 },
{ id: "VitaminB1", header: "B1", width: 50 },
{ id: "VitaminB2", header: "B2", width: 50 },
{ id: "VitaminB3", header: "B3", width: 50 },
{ id: "VitaminB5", header: "B5", width: 50 },
{ id: "VitaminB6", header: "B6", width: 50 },
{ id: "VitaminB12", header: "B12", width: 50 },
{ id: "Folate", header: "Fol", width: 50 },
{ id: "VitaminA", header: "A", width: 50 },
{ id: "VitaminC", header: "C", width: 50 },
{ id: "VitaminD", header: "D", width: 50 },
{ id: "VitaminE", header: "E", width: 50 },
{ id: "VitaminK", header: "K", width: 50 },
{ id: "Calcium", header: "Cal", width: 50 },
{ id: "Copper", header: "Cop", width: 50 },
{ id: "Iron", header: "Iron", width: 50 },
{ id: "Magnesium", header: "Mag", width: 50 },
{ id: "Manganese", header: "Mang", width: 50 },
{ id: "Phosphorus", header: "Pho", width: 50 },
{ id: "Potassium", header: "Pot", width: 50 },
{ id: "Selenium", header: "Sel", width: 50 },
{ id: "Sodium", header: "Sod", width: 50 },
{ id: "Zinc", header: "Zinc", width: 50 },
],
scrollX: true,
//scroll: 'xy',
data: data
}
Thanks for any suggestions!
Update 2021-06-11
Aquatic's answer below works well in the codepen. (Thank you Aqauatic!)
However, when I use this treetable in an ASP.NET Core application with the default styling, it looks like this:
Note the following:
The footer and table overlap
The scrollbar is applied to the entire page, instead of just the table.
It appears that the treeview goes out of bounds of the enclosing div.
As suggested by Aquatic, I have a div:
<div style="width: 800px; height: 400px;" id="abc"></div>
Then I reference abc from webix:
webix.ready(function () {
webix.ui({
container: "abc",
Here's a codepen with the CSS copied over from Chrome tools:
https://codepen.io/dharmatech/pen/LYWgyMN
Here's a link to the ASP.NET Core cshtml file on github (as well as the rest of the entire project):
https://github.com/dharmatech/NutritionTrackerRazorPages-2021-05-27-07-32/blob/8207bbd0f6162c8b1a752d8941ea153dd04a1cef/Pages/FoodRecords/IndexWebix.cshtml
If I hardcode the width and height as follows:
{
view: "treetable",
//responsive: true,
id: "grida",
//autowidth: true,
//autoheight: true,
width: 800,
height: 500,
the treeview is properly bounded:
however, it does not resize as the window is resized.
Any suggestions are welcome!
Your code is correct. And TreeTable does show all columns, you just miss the horizontal scroll at bottom of the grid.
To fix the situation, you need to
init UI in container ( currently it is atached to the body ). To do so you need to add container property to the UI configuration
<div id="tree_here">
</div>
webix.ui({
container:"tree_here",
rows: [
be sure to define sizes for the container
#container{
width: 100%;
height: 300px;
}
https://codepen.io/mkozhukh/pen/MWpPwpP

issue in showing pager after reloading the jqxgrid data on click event

I am trying to reload the grid on click event. Here is my code for grid
var source = {
datatype: "json",
datafields: [
{ name: 'sno' },
{ name: 'bid' },
{ name: 'city' },
{ name: 'booking_date' },
{ name: 'amount' },
{ name: 'customer_contact' },
{ name: 'user_name' },
{ name: 'trip_type' },
{ name: 'comments' },
{ name: 'action' },
],
cache: false,
url: 'order_details.php?flag=2&start_date='+start_date_param+'&end_date='+end_date_param,
data: {
pagesize:50
},
root: 'Rows',
//sortcolumn: 'area',
// sortdirection: 'asc',
beforeprocessing: function (data) {
source.totalrecords = data[0].TotalRows;
}
};
dataadapter = new $.jqx.dataAdapter(source);
// initialize jqxGrid
$("#jqxgrid").jqxGrid(
{
width: 1100,
source: dataadapter,
theme: 'classic',
autoheight: true,
pageable: true,
pagesize:50,
enablebrowserselection: true,
selectionmode: 'singlecell',
//sortable:true,
virtualmode: true,
rendergridrows: function (params) {
return params.data;
},
columns:
[
{ text: 'No', datafield: 'sno', width: 30 },
{ text: 'Booking Id', datafield: 'bid', width: 90, align: 'center',cellsAlign: 'center' },
{ text: 'City', datafield: 'city', width: 170 },
{ text: 'Car Book Date', datafield: 'booking_date', width: 100, align: 'center',cellsAlign: 'center' },
{ text: 'Amount', datafield: 'amount', width: 60, align: 'right',cellsAlign: 'right' },
{ text: 'Customer Contact', datafield: 'customer_contact', width: 205 },
{ text: 'User Name', datafield: 'user_name', width: 125 },
{ text: 'Trip Type', datafield: 'trip_type', width: 160},
{ text: 'Comments', datafield: 'comments', width: 80, align: 'center',cellsAlign: 'center'},
{ text: 'Action', datafield: 'action', width: 80, align: 'center',cellsAlign: 'center'},
]
});
// event handling on select of date range and click on button show
$("#btn_show").on("click", function (e) {
e.preventDefault();
var start_date_param = $("#start_date").val();
var end_date_param = $("#end_date").val();
source.url = 'order_details.php?flag=2&start_date='+start_date_param+'&end_date='+end_date_param;
dataadapter.dataBind();
});
On click of button "btn_show", I could get the data from page 0, but if I am on page 4, then after click event, my grid pager is remains on page 4 only and data is display for page 0.If I click on next page, then it jumps from page 0 to next page i.e page 5.
Why jqxgrid is not resetting its recordedstartindex and recordedendindex values on dataadapter.dataBind() call after click event?
Do I need to use any other function to reload my complete grid??
I think that the following:
$("#jqxgrid").jqxGrid('gotopage', 0);
should replace
dataadapter.dataBind();
In your code.

Two pies, one legend with unique items (merge legends)

Is it possible to do two pies in one graphic and merge legends?
I did this : http://jsfiddle.net/Adysone/YpfBs/
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'pie'
},
title: {
text: "Pie Charts",
align: 'center'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top'
},
tooltip: {
formatter: function () {
return this.key + ': ' + this.y + ' (' + Math.round(this.percentage) + '%)';
}
},
plotOptions: {
pie: {
showInLegend: true,
size: 200
}
},
series: [
{
name: "2011",
data: [
{
name: "Apple",
color: "#FF3333",
y: 8
},
{
name: "Banana",
color: "#FFF55C",
y: 11
},
{
name: "Grape",
color: "#90007B",
y: 9
},
{
name: "Pear",
color: "#F1FFB8",
y: 3
}
],
center: [150,100],
size: 150
},
{
name: "2012",
data: [
{
name: "Apple",
color: "#FF3333",
y: 5
},
{
name: "Banana",
color: "#FFF55C",
y: 15
},
{
name: "Pear",
color: "#F1FFB8",
y: 8
}
],
center: [450,100],
size: 150
}
]
});
But legend items are duplicated since they are common in the two pies, how can I do to make these unique?
If it's not possible, can I make two legends separate?
Thanks!
Please take look at example http://jsfiddle.net/u7FQS/15/ which used 3 pie charts and has common legend
$(chart.series[0].data).each(function(i, e) {
e.legendItem.on('click', function(event) {
var legendItem=e.name;
event.stopPropagation();
$(chart.series).each(function(j,f){
$(this.data).each(function(k,z){
if(z.name==legendItem)
{
if(z.visible)
{
z.setVisible(false);
}
else
{
z.setVisible(true);
}
}
});
});
});
});

JqGrid not loading in web page in asp.net mvc3

I am having an aspx engine view where the jqgrid must be loaded.
But the jqgrid is not loading. I tried with breakpoint using firebug but it has not hitted also
In the view
<asp:Content ID="Content3" ContentPlaceHolderID="MetaContent" runat="server">
<table id="jqgprojectnew" style="width: 100%">
</table>
<script type="text/javascript">
var url = '<%#Url.Action("Listmanoj")%>';
var colNames = [
'Orderid',
'Customername',
'Price',
'Quantity',
'Productname',
'Total Including Tax',
'Email',
'Town',
'Country', 'Postcode', 'Homephone','Workphone','Deliveryname','Deliverytown','Deliveryphone','Deliverypostalcode','Shippingmethod'];
var colModel = [
{ name: 'Orderid', index: 'Orderid', align: 'left', width: 20 },
{ name: 'Customername', index: 'Customername', edittype: 'image', align: 'left', width: 70, },
{ name: 'Price', index: 'Price', align: 'left', width: 100, },
{ name: 'Quantity', index: 'Quantity', align: 'left', width: 150, },
{ name: 'Productname', index: 'Productname', align: 'left', width: 150 },
{ name: 'Totalincludingtax', index: 'Totalincludingtax', align: 'left', width: 150 },
{ name: 'Email', index: 'Email', align: 'left', width: 100, },
{ name: 'Town', index: 'Town', align: 'left', width: 100 },
{ name: 'Country', index: 'Country', align: 'left', width: 100, },
{ name: 'Postcode', index: 'Postcode', align: 'left', width: 70 },
{ name: 'Homephone', index: 'Homephone', align: 'left', width: 70 },
{ name: 'Workphone', index: 'Workphone', align: 'left', width: 70 },
{ name: 'Deliveryname', index: 'Deliveryname', align: 'left', width: 70 },
{ name: 'Deliverytown', index: 'Deliverytown', align: 'left', width: 70 },
{ name: 'Deliveryphone', index: 'Deliveryphone', align: 'left', width: 70 },
{ name: 'Deliverypostalcode', index: 'Deliverypostalcode', align: 'left', width: 70 },
{ name: 'Shippingmethod', index: 'Shippingmethod', align: 'left', width: 70 }
];
var sortname = 'Orderid';
var sortorder = 'desc';
SetGrid('#jqgprojectnew', '', url, colNames, colModel, sortname, sortorder, -1);
});
</script>
In the Web page view how it is loading
<script type="text/javascript"> $(document).ready(function () {
$("a.button").button();
var url = '';
var colNames = [
'Orderid',
'Customername',
'Price',
'Quantity',
'Productname',
'Total Including Tax',
'Email',
'Town',
'Country', 'Postcode', 'Homephone','Workphone','Deliveryname','Deliverytown','Deliveryphone','Deliverypostalcode','Shippingmethod'];
Code for setting grid:
function SetGrid(v_gridCtrl,v_pagingCtrl, v_url, v_colNames, v_colModel, v_sortname, v_sortorder, v_Pagesize) {
if (v_Pagesize == undefined)
v_Pagesize = 100;
$(v_gridCtrl).jqGrid({
//url from wich data should be requested
autowidth: true,
url: v_url,
//type of data
datatype: 'json',
//url access method type
mtype: 'POST',
//columns names
colNames: v_colNames,
//columns model
colModel: v_colModel,
//pager for grid
pager: $(v_pagingCtrl),
//enable dynamic scrolling
//scroll: true,
//enable npage request parameter
prmNames: { npage: 'npage' },
//number of rows per page
rowNum: v_Pagesize,
rowList: [10, 30, 60, 90, 100, 150, -1],
loadComplete: function () {
$("option[value=-1]").text('All');
$('#count').html($(v_gridCtrl).getGridParam("reccount"));
},
//initial sorting column
sortname: v_sortname,
//initial sorting direction
sortorder: v_sortorder,
//we want to display total records count
viewrecords: true,
//grid height
height: 400,//'100%',
width: '100%',
scrollOffset: 0,
shrinkToFit: true
});
}
My problems are:
The action method which is used in the jqgrid is not hitind and on load the url action result is empty
Add document.ready() in script
Set url like this:
var url = '/ControllerName/Listmanoj'; //If your controller name is TestController, the url should be '/Test/Listmanoj'
Remove the following section:(why do you need that?)
$(document).ready(function () {
$("a.button").button();
var url = '';
var colNames = [
'Orderid',
'Customername',
'Price',
'Quantity',
'Productname',
'Total Including Tax',
'Email',
'Town',
'Country', 'Postcode', 'Homephone','Workphone','Deliveryname','Deliverytown','Deliveryphone','Deliverypostalcode','Shippingmethod'];
Include setGrid in document.ready().
In short, you script section should look like:
<asp:Content ID="Content3" ContentPlaceHolderID="MetaContent" runat="server">
<table id="jqgprojectnew" style="width: 100%">
</table>
<script type="text/javascript">
$(document).ready(function()
{
//set grid function
function SetGrid(v_gridCtrl,v_pagingCtrl, v_url, v_colNames, v_colModel, v_sortname, v_sortorder, v_Pagesize) {
if (v_Pagesize == undefined)
v_Pagesize = 100;
$(v_gridCtrl).jqGrid({
//url from wich data should be requested
autowidth: true,
url: v_url,
//type of data
datatype: 'json',
//url access method type
mtype: 'POST',
//columns names
colNames: v_colNames,
//columns model
colModel: v_colModel,
//pager for grid
pager: $(v_pagingCtrl),
//enable dynamic scrolling
//scroll: true,
//enable npage request parameter
prmNames: { npage: 'npage' },
//number of rows per page
rowNum: v_Pagesize,
rowList: [10, 30, 60, 90, 100, 150, -1],
loadComplete: function () {
$("option[value=-1]").text('All');
$('#count').html($(v_gridCtrl).getGridParam("reccount"));
},
//initial sorting column
sortname: v_sortname,
//initial sorting direction
sortorder: v_sortorder,
//we want to display total records count
viewrecords: true,
//grid height
height: 400,//'100%',
width: '100%',
scrollOffset: 0,
shrinkToFit: true
});
}// end of set grid function
var url = 'controllername/Listmanoj';
var colNames = [
'Orderid',
'Customername',
'Price',
'Quantity',
'Productname',
'Total Including Tax',
'Email',
'Town',
'Country', 'Postcode', 'Homephone','Workphone','Deliveryname','Deliverytown','Deliveryphone','Deliverypostalcode','Shippingmethod'];
var colModel = [
{ name: 'Orderid', index: 'Orderid', align: 'left', width: 20 },
{ name: 'Customername', index: 'Customername', edittype: 'image', align: 'left', width: 70, },
{ name: 'Price', index: 'Price', align: 'left', width: 100, },
{ name: 'Quantity', index: 'Quantity', align: 'left', width: 150, },
{ name: 'Productname', index: 'Productname', align: 'left', width: 150 },
{ name: 'Totalincludingtax', index: 'Totalincludingtax', align: 'left', width: 150 },
{ name: 'Email', index: 'Email', align: 'left', width: 100, },
{ name: 'Town', index: 'Town', align: 'left', width: 100 },
{ name: 'Country', index: 'Country', align: 'left', width: 100, },
{ name: 'Postcode', index: 'Postcode', align: 'left', width: 70 },
{ name: 'Homephone', index: 'Homephone', align: 'left', width: 70 },
{ name: 'Workphone', index: 'Workphone', align: 'left', width: 70 },
{ name: 'Deliveryname', index: 'Deliveryname', align: 'left', width: 70 },
{ name: 'Deliverytown', index: 'Deliverytown', align: 'left', width: 70 },
{ name: 'Deliveryphone', index: 'Deliveryphone', align: 'left', width: 70 },
{ name: 'Deliverypostalcode', index: 'Deliverypostalcode', align: 'left', width: 70 },
{ name: 'Shippingmethod', index: 'Shippingmethod', align: 'left', width: 70 }
];
var sortname = 'Orderid';
var sortorder = 'desc';
SetGrid('#jqgprojectnew', '', url, colNames, colModel, sortname, sortorder, -1);
});
</script>

Displaying a Blank JQGrid with Column Headers

I want to display JQGrid with all column headers but without any data rows when the page loads.
Based upon user selection through autocomplete i want to populate the JqGrid with data.
The problem is that each time during pageload the grid is automatically populated.
How can i get around this ?
This is how i am using the grid with VS2008 MVC2
jQuery('#jgrid').jqGrid({
autowidth: true,
altRows: true,
altclass: 'grdAltRwClr',
datatype: 'xml',
forceFit: true,
gridview: true,
height: 290,
mtype: 'post',
rowList: [10, 20, 30],
rowNum: 10,
pager: '#pager',
pagerpos: 'right',
recordpos: 'left',
rownumbers: false,
scrollrows: false,
sortname: 'roledtlid',
toolbar: [true, "top"],
url: rootPath + 'RoleDetail/JGridData',
beforeSelectRow: function(rowid, e) { return false; },
gridComplete: function() { GridComplete() },
colModel: [
{ name: 'act', label: 'View', resizable: false, search: false, sortable: false, title: false, width: 6, index: 'act' }
, { name: 'roledtlid', label: 'R.Detail id', width: 15, index: 'roledtlid' }
, { name: 'roleid', label: 'Role id', width: 10, index: 'roleid' }
, { name: 'rolename', label: 'Role Name', width: 25, index: 'rolename' }
, { name: 'pageid', label: 'Page ID', width: 10, index: 'pageid' }
, { name: 'pgname', label: 'Page Name', width: 30, index: 'pgname' }
, { name: 'canadd', label: 'Add', width: 10, index: 'canadd' }
, { name: 'canedit', label: 'Edit', width: 10, index: 'canedit' }
, { name: 'candel', label: 'Delete', width: 10, index: 'candel' }
, { name: 'canview', label: 'View', width: 10, index: 'canview' }
]
});
Thanks
Don't provide a url. Instead set your datatype to "local" and use code similar to the following:
var mySearchData = // Get your search data...
$.post('#Url.Action("Getars")', mySearchData, function(gridData) {
var rowIds = $('#carGrid').jqGrid('getDataIDs');
for (var i = 0, len = rowIds.length; i < len; i++) {
var currRow = rowIds[i];
$('#carGrid').jqGrid('delRowData', currRow);
}
$('#carGrid').jqGrid('setGridParam', { data: gridData }).trigger('reloadGrid');
}).error(function (jqXHR, textStatus) {
app.showErrorAlert(jqXHR.responseText);
});
}

Resources