jqgrid - resize columns doesn't work in bootstrap modal - jqgrid

based of this answer
I have a bootstrap modal that I used that function for that.
Here is the code:
Modal view file:
<div class="modal modal-wide fade" id="mo-selector-dialog" title="<bean:message key="add.ex"/>">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Add</h4>
</div>
<div class="modal-body">
<table id="moTable"></table>
<!-- <div id="pager"></div>-->
<div class="modal-footer">
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
Modal call in js file:
$('#add-link').click(function(){
$('#mo-selector-dialog').css("display", "block");
$('.mo-backdrop').css("display", "block");
mc$('#mo-selector-dialog').modal({show:true});
$('body').css("overflow-y", "hidden");
});
jqgrid:
$moGrid.bind("jqGridAfterLoadComplete jqGridRemapColumns", function () {
var $this = $(this),
$cells = $this.find(">tbody>tr.jqgrow>td"),
$colHeaders = $($.map(this.grid.headers, function (item) { return item.el; })).find(">div"),
colModel = $this.jqGrid("getGridParam", "colModel"),
cellLayout = $this.jqGrid("getGridParam", "cellLayout"),
iCol,
iRow,
rows,
row,
n = $.isArray(colModel) ? colModel.length : 0,
cm,
colWidth,
idColHeadPrexif = "jqgh_" + this.id + "_";
$cells.wrapInner("<span class='mywrapping'></span>");
$colHeaders.wrapInner("<span class='mywrapping'></span>");
for (iCol = 0; iCol < n; iCol++) {
cm = colModel[iCol];
if (cm.hidden) {
continue;
}
colWidth = $("#" + idColHeadPrexif + $.jgrid.jqID(cm.name) + ">.mywrapping").outerWidth(true) + 25; // 25px for sorting icons
for (iRow = 0, rows = this.rows; iRow < rows.length; iRow++) {
row = rows[iRow];
if ($(row).hasClass("jqgrow")) {
colWidth = Math.max(colWidth, $(row.cells[iCol]).find(".mywrapping").outerWidth(true));
}
}
$this.jqGrid("setColWidth", iCol, colWidth + ($.jgrid.cell_width? cellLayout: 0));
}
});
$moGrid.jqGrid({
height: 400,
url: 'ex/list',
sortname: 'bDt',
colNames: IS.mo.columnDisplayNames,
colModel: IS.mo.colModelDef,
beforeSelectRow: shiftSelect,
gridview: true,
rowattr: function (rd) {
return rowStyle(rd);
},
beforeRequest: IS.filter.applyFilter($moGrid, $('input, select', filterForm), IS.mo.listFilterValues),
onSelectRow: function(id, status) {
$('#messageBox ul').empty();
if (status){
var ids= $moGrid.jqGrid('getGridParam','selarrrow');
for (var i = 0; i < ids.length; i++)
{
var rowId = ids[i];
var rowData = $moGrid.jqGrid ('getRowData', rowId);
global_selectedGroupMRowData.push(rowData);
}
}else{
global_selectedGroupMRowIds.splice($.inArray(id, global_selectedGroupMRowIds), 1);
for(var i=0; i<global_selectedGroupMRowData.length; i++){
if (global_selectedGroupMRowData[i].id==id){
global_selectedGroupMRowData.splice(i, 1);
}
}
//global_selectedGroupMRowData.splice($.inArray($("#moTable").jqGrid('getRowData',id), global_selectedGroupMRowData), 1);
}
},
onSelectAll: function(aRowids, status) {
$('#messageBox ul').empty();
if (status){
for (var i = 0; i < aRowids.length; i++)
if ($.inArray(aRowids[i], global_selectedGroupMRowIds) == -1) {
global_selectedGroupMRowIds.push(aRowids[i]);
global_selectedGroupMRowData.push($("#moTable").jqGrid('getRowData',aRowids[i]));
}
} else {
for (var i = 0; i < aRowids.length; i++) {
global_selectedGroupMRowIds.splice($.inArray(aRowids[i], global_selectedGroupMRowIds), 1);
global_selectedGroupMRowData.splice($.inArray(aRowids[i], global_selectedGroupMRowData), 1);
}
}
},
loadComplete: function() {
var arraysize = global_selectedGroupMRowIds.length;
if (arraysize>0){
for (var i=0; i<arraysize; i++) {
$("#moTable").setSelection(global_selectedGroupMRowIds[i], false);
}
}
getEditPage('#moTable');
$("#moTable").find('#pager_left,#pager_center,#pager_right').hide();
}
});
It works to other pages that aren't modal. Just inside the modal it doesn't work.
Any idea?

I suppose that the problem can be fixed by changing the line
$this.jqGrid("setColWidth", iCol, colWidth + ($.jgrid.cell_width? cellLayout: 0));
so that colWidth will be increased to this.p.cellLayout (cellLayout parameter which equal to 5) if $.jgrid.cell_width is true:
$grid.on("jqGridAfterLoadComplete jqGridRemapColumns", function () {
var $this = $(this),
$cells = $this.find(">tbody>tr.jqgrow>td"),
$colHeaders = $($.map(this.grid.headers, function (item) { return item.el; })).find(">div"),
colModel = $this.jqGrid("getGridParam", "colModel"),
cellLayout = $this.jqGrid("getGridParam", "cellLayout"),
iCol,
iRow,
rows,
row,
n = $.isArray(colModel) ? colModel.length : 0,
cm,
colWidth,
idColHeadPrexif = "jqgh_" + this.id + "_";
$cells.wrapInner("<span class='mywrapping'></span>");
$colHeaders.wrapInner("<span class='mywrapping'></span>");
for (iCol = 0; iCol < n; iCol++) {
cm = colModel[iCol];
if (cm.hidden) {
continue;
}
colWidth = $("#" + idColHeadPrexif + $.jgrid.jqID(cm.name) + ">.mywrapping").outerWidth(true) + 25; // 25px for sorting icons
for (iRow = 0, rows = this.rows; iRow < rows.length; iRow++) {
row = rows[iRow];
if ($(row).hasClass("jqgrow")) {
colWidth = Math.max(colWidth, $(row.cells[iCol]).find(".mywrapping").outerWidth(true));
}
}
$this.jqGrid("setColWidth", iCol, colWidth + ($.jgrid.cell_width? cellLayout: 0));
}
});
The demo uses Bootstrap 3.2 and Font Awesome 4.2. Another demo uses the same code to autowidth of columns and it works too.
UPDATED: See one more demo.

Related

Create transparent background image from text input

i just trying to do create image from text input value which i want to transparent background, but somehow somewhere there is a mistake which i couldn't find. http://jsfiddle.net/e4f3Lc6n/
When i change the var backgroundColor = "transparent"; to any color it works like a charm. but you can see in jsfiddle link it is writing over the previous text when it is transparent. For my project there should be no color background. Where am i making a mistake?
Thanks for any help...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Text Arranger</title>
<link rel="stylesheet" href="../poetry/poetry_stylesheet.css" type="text/css"/>
<link rel="stylesheet" href="../index_stylesheet.css" type="text/css"/>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46245008-1', 'peteymac.com');
ga('send', 'pageview');
</script>
<script type="text/javascript">
window.addEventListener("load", eventWindowLoaded, false);
var Debugger = function() {};
Debugger.log = function(message) {
try {
console.log(message);
} catch (exception) {
return;
}
}
function eventWindowLoaded () {
canvasApp();
}
function canvasSupport () {
return !!document.createElement("canvas").getContext;
}
function canvasApp () {
Debugger.log("Drawing Canvas");
if(!canvasSupport()) {
return;
}
var theCanvas = document.getElementById('canvasOne');
var context = theCanvas.getContext('2d');
WIDTH = theCanvas.width;
HEIGHT = theCanvas.height;
var message = "canberk";
var fontSize = "50";
var fontFace = "serif";
var fontWeight = "normal"
var fontStyle = "normal";
var textFillColor = "#ff0000";
var backgroundColor = "transparent";
var textStrokeColor = "#000000";
var fillOrStroke = "fill";
var textBaseline = "middle";
var textAlign = "center";
var fillType = "colorFill";
// This is the event handler for listening for a key up event in the text box form
// It will call the textBoxChanged function to update the text in the canvas
var formElement = document.getElementById("textBox");
formElement.addEventListener("keyup", textBoxChanged, false);
formElement = document.getElementById("textSize");
formElement.addEventListener("change", textSizeChanged, false);
formElement = document.getElementById("textFont");
formElement.addEventListener("change", textFontChanged, false);
formElement = document.getElementById("fontWeight");
formElement.addEventListener("change", fontWeightChanged, false);
formElement = document.getElementById("fontStyle");
formElement.addEventListener("change", fontStyleChanged, false);
formElement = document.getElementById("fillType");
formElement.addEventListener("change", fillTypeChanged, false);
formElement = document.getElementById("textFillColor");
formElement.addEventListener("change", textFillColorChanged, false);
formElement = document.getElementById("createImageData");
formElement.addEventListener("click", createImageDataPressed, false);
drawScreen();
function drawScreen() {
var metrics = context.measureText(message);
var textWidth = metrics.width;
var xPosition = WIDTH / 2
var yPosition = HEIGHT / 2;
// Draws the Text Box
context.globalAlpha = 1.0;
context.fillStyle = backgroundColor;
context.fillRect(0,0,WIDTH,HEIGHT);
// Draws the actual text
context.font = fontWeight + " " + fontStyle + " " + fontSize + "px " + fontFace;
context.textBaseline = textBaseline;
context.textAlign = textAlign;
var tempColor;
switch(fillType) {
case "colorFill":
Debugger.log("Color Fill");
tempColor = textFillColor;
break;
case "linearGradient":
Debugger.log("Linear Gradient");
var linGradient = context.createLinearGradient(xPosition-textWidth/2, yPosition, xPosition+textWidth/2, yPosition);
linGradient.addColorStop(0, textFillColor);
tempColor = linGradient;
break;
case "radialGradient":
Debugger.log("Radial Gradient");
var radGradient = context.createRadialGradient(xPosition, yPosition, 1, xPosition, yPosition, textWidth/2);
radGradient.addColorStop(0, textFillColor);
tempColor = radGradient;
break;
}
switch(fillOrStroke) {
case "fill":
context.fillStyle = tempColor;
context.fillText(message, xPosition, yPosition);
break;
case "stroke":
context.strokeStyle = textStrokeColor;
context.strokeText(message, xPosition, yPosition);
break;
case "both":
context.fillStyle = tempColor;
context.fillText(message, xPosition, yPosition);
context.strokeStyle = textStrokeColor;
context.strokeText(message, xPosition, yPosition);
break;
}
}
function textBoxChanged(e) {
var target = e.target;
message = target.value;
drawScreen();
}
function textSizeChanged(e) {
var target = e.target;
fontSize = target.value;
drawScreen();
}
function textFontChanged(e) {
var target = e.target;
fontFace = target.value;
drawScreen();
}
function fontWeightChanged(e) {
var target = e.target;
fontWeight = target.value;
drawScreen();
}
function fontStyleChanged(e) {
var target = e.target;
fontStyle = target.value;
drawScreen();
}
function fillTypeChanged(e) {
var target = e.target;
fillType = target.value;
drawScreen();
}
function textFillColorChanged(e) {
var target = e.target;
textFillColor = "#" + target.value;
drawScreen();
}
function createImageDataPressed(e) {
var imageDataDisplay = document.getElementById("imageDataDisplay");
imageDataDisplay.value = theCanvas.toDataURL();
}
}
</script>
<style>
#canvasOne {
box-shadow: -4px -4px 5px #aaaaaa;
display: block;
margin-left: -60px;
}
form {
margin-top: 40px;
}
</style>
</head>
<body>
<canvas id="canvasOne" width="1000" height="250">
Your browser does not support Canvas.
</canvas>
<form>
Text: <input id="textBox" value="canberk"/>
<br/>
Text Font: <select id="textFont">
<option value = "serif">Serif</option>
<option value = "sans-serif">Sans-Serif</option>
<option value = "cursive">Cursive</option>
<option value = "fantasy">Fanatasy</option>
<option value = "monospace">Monospace</option>
</select>
Font Weight: <select id="fontWeight">
<option value="normal">Normal</option>
<option value="bold">Bold</option>
<option value="bolder">Bolder</option>
<option value="lighter">Lighter</option>
</select>
Font Style: <select id="fontStyle">
<option value="normal">Normal</option>
<option value="italic">Italic</option>
<option value="oblique">Oblique</option>
</select>
<br/>
Text Size: <input type="range" id="textSize"
min="0"
max="200"
step="1"
value="50"/>
<br/>
Fill Type: <select id="fillType">
<option value="colorFill">Color Fill</option>
<option value="linearGradient">Linear Gradient</option>
<option value="radialGradient">Radial Gradient</option>
</select>
<br/>
Text Fill Color: <input id="textFillColor" value="ff0000"/>
<input type="button" id="createImageData" value="Create Data Image">
<br/>
<textarea id="imageDataDisplay" rows=5 cols=100></textarea>
</form>
</div>
</body>
</html>
I think the solution you need is:
function drawScreen() {
context.clearRect(0, 0, WIDTH, HEIGHT);
...
...
}

First column of my DataTable has same width that all DataTable header

I set the headers of my DataTable dynamically
for (i = 0; i < nvs; i++) {
var id = i + 1;
$("#headersgrid").append(
'<th id="header' + id + '">header</th>'
);
parametros[i] = $("#vsdata" + id).text();
$("#header" + id).text(parametros[i]);
}
After that I have this code for my Ajax request:
$("#spresultado-datatable").DataTable({
responsive: true,
destroy: true,
"processing": true,
"serverSide": false,
"filter": true,
"ordering": true,
//"autoWidth": false,
"language": {
"processing": "Procesando...",
"lengthMenu": "Mostrar _MENU_ registros por pagina",
"zeroRecords": "No se encontraron resultados",
"info": "Mostrando pagina _PAGE_ de _PAGES_",
"infoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
"infoFiltered": "(filtrado de un total de _MAX_ registros)",
"paginate": {
"first": "Primero",
"last": "Último",
"next": "Siguiente",
"previous": "Anterior"
}
},
"ajax": {
"url": "/Spconsumer/Ejecutar",
"type": "POST",
"data": DTO,
"datatype": "json",
"dataSrc": function (response) {
var i = 0;
var j = 0;
for (j = 0; j < response.data.length; j++) {
columns = [];
$.each(response.data[j].parametro, function (key, value) {
var my_item = {};
var id = i + 1;
my_item.data = value;
my_item.name = parametros[i];
//my_item.autoWidth = true;
columns.push(value);
i++;
});
data.push(columns);
}
return data;
},
"columnDefs": [
{ "autoWidth": true , "targets": 0 }
]
}
});
I get the data correctly and pass it to my Index.cshtml in order to show the table:
<div class="users-list-table" id="gridresultadosp">
<div class="card">
<div class="card-header row">
<div class="col-12 col-sm-6 col-lg-8">
<h1 class="card-title">Spconsumer - Resultado Ejecucion SP</h1>
</div>
</div>
<div class="card-content">
<div class="card-body">
<!-- datatable start -->
<div class="table-responsive">
<table id="spresultado-datatable" class="table mb-0">
<thead>
<tr id="headersgrid">
</tr>
</thead>
</table>
</div>
<!-- datatable ends -->
</div>
</div>
</div>
</div>
I am getting the data correctly in my Html but I have a problem with the first column:
As you can see in the image the data loads correctly, ordering and filtering work ok but the width of the first column spans the full width of the entire header of the data table. I tried everything, search the internet without success, please if someone can guide me on how to solve it
I managed to resolve the problem:
I changed:
for (i = 0; i < nvs; i++) {
var id = i + 1;
$("#headersgrid").append(
'<th id="header' + id + '">header</th>'
);
parametros[i] = $("#vsdata" + id).text();
$("#header" + id).text(parametros[i]);
}
To
for (i = 0; i < nvs; i++) {
var id = i + 1;
parametros[i] = $("#vsdata" + id).text();
$("#headersgrid").append(
'<th>' + parametros[i] + '</th>'
);
}
Using <th id="header' + id + '">header</th> was the origin of the problem

Regarding Vue function in dashboard

We are experiencing problems after a Vue update. However, we cannot locate the error. Could anyone help us find this problem? This has occurred in the dashboard at a certain section where we show the payments from our users, so the admins can look into this.
The code:
addCollection: function (employee) {
var self = this;
year = 0;
var selectText =
'<div class="swal2-content" style="display: block;">Periode:</div>';
selectText +=
'<select id="swal-select1" class="swal2-select form-control" style="display: inline-block; width: calc(50% - 4px); margin-right: 4px;">';
for (year in self.vmAvailableYears) {
alert(this.year);
selectText +=
'<option value="' +
self.vmAvailableYears[year] +
'" ' +
(self.vmAvailableYears[year] == self.vmCurrentYear
? "selected"
: "") +
">" +
self.vmAvailableYears[year] +
"</option>";
}
selectText += "</select>";
selectText +=
'<select id="swal-select2" class="swal2-select form-control" style="display: inline-block; width: calc(50% - 4px); margin-left: 4px;">';
for (i = 1; i < 52; i++) {
selectText +=
'<option value="' +
i +
'" ' +
(i == self.vmCurrentWeek ? "selected" : "") +
">week " +
i +
"</option>";
}
selectText += "</select>";
selectText +=
'<div class="swal2-content" style="display: block;">Type:</div>';
selectText +=
'<select id="swal-select3" class="swal2-select form-control">';
selectText +=
'<option value="rent" style="' +
(self.vmCanAlter ? "" : "display: none;") +
'" data-amount-required="true" data-comment-required="false">Huur</option>';
selectText +=
'<option value="addition" data-amount-required="true" data-comment-required="true">Extra kosten</option>';
selectText +=
'<option value="payment_cash" selected data-amount-required="true" data-comment-required="false">Betaling contant</option>';
selectText +=
'<option value="payment_card" data-amount-required="true" data-comment-required="false">Betaling PIN</option>';
selectText +=
'<option value="payment_transfer" data-amount-required="true" data-comment-required="false">Betaling overboeking</option>';
selectText +=
'<option value="vacation_unpaid" data-amount-required="false" data-comment-required="false">Vakantie (doorbetalen)</option>';
selectText +=
'<option value="vacation_paid" data-amount-required="false" data-comment-required="false">Vakantie (niet doorbetalen)</option>';
selectText +=
'<option value="remission" data-amount-required="true" data-comment-required="true">Kwijtschelding</option>';
selectText +=
'<option value="comment" data-amount-required="false" data-comment-required="true">Opmerking</option>';
selectText += "</select>";
selectText +=
'<div id="swal-label1" class="swal2-content" style="display: block;">Bedrag:</div>';
selectText +=
'<input id="swal-input1" class="swal2-input" placeholder="Bedrag">';
selectText +=
'<div class="swal2-content" style="display: block;">Opmerking (<span id="swal-comment-label">optioneel</span>):</div>';
selectText +=
'<input id="swal-input2" class="swal2-input" placeholder="Opmerking">';
self
.$swal({
title:
employee.firstname +
" " +
employee.insertion +
" " +
employee.lastname,
html: selectText,
showCancelButton: true,
confirmButtonText: "Toevoegen",
cancelButtonText: "Annuleren",
showLoaderOnConfirm: true,
allowOutsideClick: false,
onOpen: function (el) {
$(el)
.find("#swal-select3")
.on("change", function () {
var selectedOption = $("option:selected", this);
var amountRequired = selectedOption.data("amount-required");
var commentRequired = selectedOption.data("comment-required");
var amountLabel = $("#swal-label1");
var amountInput = $("#swal-input1");
var commentInput = $("#swal-input2");
if (amountRequired) {
amountLabel.show();
amountInput.show();
} else {
amountLabel.hide();
amountInput.val("");
amountInput.hide();
}
commentInput.prop("required", commentRequired);
$("#swal-comment-label").text(
commentRequired ? "verplicht" : "optioneel"
);
});
$(el)
.find("#swal-select1, #swal-select2")
.on("change", function () {
const rentOption = $('#swal-select3 option[value="rent"]');
if (
self.vmCanAlter ||
self.weekIsInFuture(
$("#swal-select1").val(),
$("#swal-select2").val()
)
) {
rentOption.show();
} else {
rentOption.hide();
if ($("#swal-select3").val() == "rent") {
$("#swal-select3").val("payment_cash");
}
}
});
},
preConfirm: function (key) {
return new Promise(function (resolve, reject) {
if (
$("#swal-input2").prop("required") &&
$("#swal-input2").val().length <= 0
) {
reject("Opmerking is een verplicht veld.");
}
var postData = {
employee_id: employee.id,
type: $("#swal-select3").val(),
amount: $("#swal-input1").val().replace(",", "."),
comment: $("#swal-input2").val(),
year: $("#swal-select1").val(),
week: $("#swal-select2").val(),
};
self.resourceCollection.store(postData).then(
(response) => {
handleRequestSuccess(response);
resolve(response.data);
},
(response) => {
let handledResponse = handleRequestError(response);
if (handledResponse) {
reject(self.formatErrors(response.data));
}
}
);
});
},
})
.then(
(response) => {
let amount = parseFloat(response.amount);
if (["rent", "addition"].indexOf(response.type) > -1) {
employee.balance -= amount;
} else {
employee.balance += amount;
}
if (response.rent_subtract > 0) {
employee.collections.filter((collection) => {
employee.balance += parseFloat(collection.amount);
if (collection.type === "rent") {
collection.amount = 0;
}
});
}
employee.collections.push({
year: response.year,
week: response.week,
type: response.type,
amount: response.amount,
comment: response.comment,
admin: response.admin,
});
},
(rejection) => {}
);
}
The error:
[Vue warn]: Error in v-on handler: "ReferenceError: Can't find variable: year"
found in
---> <NdAdminCollectionEmployee> at resources/assets/js/vue/views/admin/collection/NdAdminCollectionEmployee.vue
<Root>
The other error:
ReferenceError: Can't find variable: year —
Kind regards,
Daan IV & Collin III

My geojson polygon doesn't appear on the ajax-leaflet map

This is my first time to make a GIS app with CodeIgniter, Leaflet, and Ajax. I want to show a polygon above my map with geojson file that I've made using geojson.io but the polygon doesn't show. When I inspect the page in my browser it shows an error message like
Failed to load modules/jenis_hutan/...geojson/map.geojson:1
resource: the server responded with a status of 404()
Here is my js code to show the geojson file.
let tnSelect = $("#tn-select");
let gisCard = $("#gis-card");
let divModal = $(".div-modal");
tnSelect.change(function () {
let $val = $(this).val();
loadPage();
setCookie("tn_value", $val, 0.0833333);
window.location.reload(true);
});
$(window).on("load", function () {
let $tn_val = getCookie("tn_value");
let gisMap;
$.ajax({
method: "GET",
url: base_url + "ajax/tn_data",
dataType: "JSON",
data: {},
success: (res) => {
console.log(res);
if ($tn_val !== null) {
for (let i = 0; i < res.length; i++) {
let data = res[i];
let name = data.tn_name;
name = name.replace(
/^[\u00C0-\u1FFF\u2C00-\uD7FF\w]|\s[\u00C0-\u1FFF\u2C00-\uD7FF\w]/g,
function (letter) {
return letter.toUpperCase();
}
);
if (data.tn_id == $tn_val) {
tnSelect.append(
'<option selected id="tn_name" value="' +
data.tn_id +
'">' +
name +
"</option>"
);
gisCard.html(
'<div class="card mb-4 gis-card">' +
'<div class="card-header py-3 text-center">' +
'<h6 class="m-0 font-weight-bold text-center">' +
name +
"</h6>" +
"</div>" +
'<div class="card-body" id="gis-map"></div>' +
"</div>"
);
gisMap = L.map("gis-map").setView([data.tn_lat, data.tn_long], 12);
mapAPI.addTo(gisMap);
} else {
tnSelect.append(
'<option value="' + data.tn_id + '">' + name + "</option>"
);
}
}
} else {
for (let i = 0; i < res.length; i++) {
let data = res[i];
let name = data.tn_name;
name = name.replace(
/^[\u00C0-\u1FFF\u2C00-\uD7FF\w]|\s[\u00C0-\u1FFF\u2C00-\uD7FF\w]/g,
function (letter) {
return letter.toUpperCase();
}
);
if (i < 1) {
tnSelect.append(
'<option selected id="tn_name" value="' +
data.tn_id +
'">' +
name +
"</option>"
);
gisCard.html(
'<div class="card mb-4 gis-card">' +
'<div class="card-header py-3 text-center">' +
'<h6 class="m-0 font-weight-bold text-center">' +
name +
"</h6>" +
"</div>" +
'<div class="card-body" id="gis-map"></div>' +
"</div>"
);
gisMap = L.map("gis-map").setView([data.tn_lat, data.tn_long], 12);
mapAPI.addTo(gisMap);
} else {
tnSelect.append(
'<option value="' + data.tn_id + '">' + name + "</option>"
);
}
}
}
//**//
$.getJSON(base_url + "modules/jenis_hutan/geojson/map.geojson", function (
data
) {
geoLayer = L.geoJson(data, {
style: function (feature) {
return {
fillOpacity: 0.5,
weight: 1,
opacity: 1,
color: "#fa7268",
};
},
onEachFeature: function (feature, layer) {
var kode = feature.properties.kode;
var info_zona = "<h5 style='text-align:left'>ZONA INTI</h5>";
info_zona += "<hr>";
info_zona +=
"<div style='width:100%;text-align:left;margin-top:10px;'><h6>Luas area: 10.475 ha</h6><br><h6>Fungsi zona: Jalur pendakian</h6></div>";
layer.bindPopup(info_zona, {
maxWidth: 260,
closeButton: true,
offset: L.point(0, -20),
});
layer.on("click", function () {
layer.openPopup();
});
},
}).addTo(map);
});
},
});
});
Is there something wrong with my code? This is my college task and the deadline is this Friday so please anyone enlight me:( or at least give me link to some tutorial related to this thing:( Thank you everyone.

how to bind a gridview from the session in mvc3

I have a partial view.in this partial view,i have a webgrid.I want to bind gridview from the session value.My code is
#{
var properties = typeof(SLCCentral.Portal.Models.Entities.ApplicationModule).GetProperties();
var webGridColumns = properties.Select(prop => new WebGridColumn()
{
ColumnName = prop.Name,
Header = prop.Name
}).ToList();
var grid = new WebGrid(source: Model, canSort: false, canPage: true, rowsPerPage: 10);
var pager = grid.Pager();
var index = grid.PageIndex;
index = index + 1;
var cnt = grid.PageCount;
//var selectedIndex = "<span class=" + "webgrid-footer-selected" + ">" + index.ToString() + "</span>";
var pgarrow = "class=" + "webgrid-footer-arrow" + "><img";
var tblcss = "<table width=" + "100%" + " cellspacing=" + "0" + " cellpadding=" + "0" + " border=" + "0" + ">";
var adthcss = "class=" + "HD-td-width-col_AppAddModule" + "> </th>";
var epthcss = "class=" + "HD-td-width-col_AppEdit" + "> </th>";
var dthcss = "class" + "HD-td-width-col_AppDelete" + "> </th>";
// var pager = grid.Pager().ToString();
if (index == 2)
{
}
var tblHTML = grid.Table().ToHtmlString();
//var Pager = System.Text.RegularExpressions.Regex.Replace(grid.Pager().ToString(), index.ToString(), selectedIndex);
//var newPager = System.Text.RegularExpressions.Regex.Replace(pager, "(( \\d)|(\\d )|(<a([^a]*|a[^>])*a>))", "<span>$1</span>");
var gridHtml = grid.GetHtml(footerStyle: "webgrid-footer-Group",
mode: WebGridPagerModes.All, nextText: "Active-NXT", previousText: "Active-PRV", numericLinksCount: 5,
columns: grid.Columns(
grid.Column(columnName: "moduleName", header: "Modules Name", style: "HD-td-width-col_ModuleName", format: #<text><span class=" moduleName">#item.moduleName</span></text>),
grid.Column(columnName: "moduleShortCode", header: "ModuleShortCode", style: "HD-td-width-col_ModuleName", format: #<text><span class=" moduleName">#item.moduleShortCode</span></text>),
grid.Column(header: "Edit", style: "HD-td-width-col_AppEdit", format: #<text><span id="edit" style="cursor:pointer;text-decoration:underline;" onclick='doEdit("")'><img src="../../Images/edit-icon.png" alt="" width="18" height="19" title="Edit" /></span></text>),
grid.Column(header: "Delete", style: "HD-td-width-col_AppDelete", format: #<text><span id="delete" style="cursor:pointer;text-decoration:underline;" onclick='PerformDelete("")'><img src="../../Images/delete-icon.png" alt="" width="16" height="21" title="Delete" /></span></text>))).ToString();
//gridHtml = System.Text.RegularExpressions.Regex.Replace(gridHtml, index.ToString(), selectedIndex);
gridHtml = System.Text.RegularExpressions.Regex.Replace(gridHtml, "<table>", tblcss);
gridHtml = System.Text.RegularExpressions.Regex.Replace(gridHtml, ">AddModules</th>", adthcss);
gridHtml = System.Text.RegularExpressions.Regex.Replace(gridHtml, ">Edit</th>", epthcss);
gridHtml = System.Text.RegularExpressions.Regex.Replace(gridHtml, ">Delete</th>", dthcss);
}#(new HtmlString(gridHtml))
public void AddModule(string ModuleName, string ModuleShortcode)
{
try
{
if (!string.IsNullOrEmpty(ModuleName))
{
_objIApplicationManagerBAL.SetModuleCol(ModuleName, ModuleShortcode);
_objIApplicationModuleCol = _objISessionContext.IModuleContextCol;
}
}
catch (Exception ex)
{
}
finally
{
}
}
You can bind value in grid by using call script and by Partialview
Script
<script type="text/javascript">
$(document).ready(function () {
firstDDLValue = "Your Session Value"
$.get('#Url.Action("YourMethod")', { secondValue: firstDDLValue }, function (result) {
$('#div-grid-id').html(result);
});
});
</script>
Control:
public ActionResult YourMethod(Viewname model, string secondValue)
{
if (secondValue != "")
ObservableCollection<Yourviewnam> Yourviewnam= new ObservableCollection<Yourviewnam>();
Yourviewnam Yourviewnam= new Models.Yourviewnam();
result= Receipt.GetReceiptListByCustID(secondValue);
return PartialView("PratialViewname", result);
}
Create an PartialView cshtml and write the code for gridview as like in your main view..I feel it will works fine.

Resources