SWFupload - passing variable from form with upload - variables

I am refering to the simpledemo in this question http://demo.swfupload.org/v220/simpledemo/index.php
I want to be able to pass a variable which is set by a dropdown menu.
the uploader is initiated by
var swfu;
window.onload = function() {
var settings = {
flash_url : "<?php global_data::show_admin_dir(); ?>SWFUpload v2.2.0.1 Samples/demos/swfupload/swfupload.swf",
upload_url: "<?php global_data::show_admin_dir(); ?>upload.php",
post_params: {"PHPSESSID" : "<?php echo session_id(); ?>" },
file_size_limit : "100 MB",
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : 100,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel"
},
debug: false,
// Button settings
button_image_url: "images/TestImageNoText_65x29.png",
button_width: "95",
button_height: "29",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '<span class="theFont">UPLOAD</span>',
button_text_style: ".theFont { font-size: 16; }",
button_text_left_padding: 12,
button_text_top_padding: 3,
// The event handler functions are defined in handlers.js
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
queue_complete_handler : queueComplete // Queue plugin event
};
swfu = new SWFUpload(settings);
};
and the form is as follows
<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
<p><label>Category: </label><input type="radio" name="for" class="radio" value="category" checked="checked" /><select name="foo"><option>...</option><?php global_data::show_breadcrum_list( 'option', " / " ); ?></select></p>
<p><label>Product: </label><input type="radio" name="for" class="radio" value="category" /><select disabled="disabled"><option name="foo">...</option><?php global_data::show_breadcrum_list( 'option', " / " ); ?></select></p>
<div class="fieldset flash" id="fsUploadProgress">
<span class="legend">Upload Queue</span>
</div>
<div id="divStatus">0 Files Uploaded</div>
<div>
<span id="spanButtonPlaceHolder"></span>
<input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
</div>
</form>
if anyone could point me in the right direction it would be much appreciated.
###### EDIT #####
I may have found a way...
using post_params: {"PHPSESSID" : "<?php echo session_id(); ?>", "PR" : thing },
in the init settings and wrapping it all in a function
function loader( thing ) {
....
}
and then using
$(document).ready(function(){
$('select[name=foo]').change(function(){
loader( $(':selected', this).text() );
});
});
it will work, but if i change the select option a second time before uploading it will get an error and only send the first choice instead of the second...

I was trying to do a similar thing and after finding this solution and discussing it with my collegue, we solved it yet another way using the Javascript API available with swfupload.
We were trying to pass a quality setting along with video uploads. Ultimately the solutions to this problem involve how to change post_params. To start with post_params will be the default value of the dropdown:
var selected_quality = $('select#quality-".$dirId." option:selected').val();
...
post_params: {'quality' : selected_quality},
Then you can use the addPostParam method (located in swfupload.js) to update this when options are selected in your dropdown.
$('select#quality-".$dirId."').change(function () {
swfu.addPostParam('quality' , this.value);
});

I have solved this problem in two ways (both using jquery): cookies and mysql. The concept would be a
$('select[name=foo]').change(function(){
$.cookie('dropdown', $(this).val());
});
so that when you change the dropdown, you now have a cookie. in upload.php you can then call that cookie and use it as your variable.
The other option was
$('select[name=foo]').change(function(){
$.post('updatedatabase.php', {'dropdown': $(this).val()});
});
Then you'd call your database from upload.php to get the last value of your dropdown. neither way is very elegant, but I've gotten them working before. I would love if someone posted a more elegant solution.

######## EDIT #######
Right this works a charm.
$(function() {
function loader( thing ) {
var settings = {
flash_url : admin_dir + "SWFUpload v2.2.0.1 Samples/demos/swfupload/swfupload.swf",
upload_url: web_root + "pm_admin/upload_image",
post_params: { "aj" : "true", "PR" : thing },
file_size_limit : "100 MB",
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : 100,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel"
},
debug: false,
// Button settings
button_image_url: "images/TestImageNoText_65x29.png",
button_width: "95",
button_height: "29",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '<span class="theFont">UPLOAD</span>',
button_text_style: ".theFont { font-size: 16; }",
button_text_left_padding: 12,
button_text_top_padding: 3,
// The event handler functions are defined in handlers.js
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
queue_complete_handler : queueComplete // Queue plugin event
};
swfu = new SWFUpload(settings);
};
function pre_load(){
var data = '';
data += '<div class="fieldset flash" id="fsUploadProgress">';
data += ' <span class="legend">Upload Queue</span>';
data += '</div>';
data += '<div id="divStatus">0 Files Uploaded</div>';
data += '<div>';
data += ' <span id="spanButtonPlaceHolder"></span>';
data += ' <input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />';
data += '</div>';
return data;
}
/* args stores the input/select/textarea/radio's name and then it's value and then passes a single serialised string when uploading */
/* then use a trigger to update the array, off focus, change, keyup... along thos lines on a class set for all inputs, selects and so on... works a treat */
var args = {};
$('.radio').click(function(){
var ob = $(this).siblings('select');
$('#uploader-wrapper').html(pre_load());
$('.radio').siblings('select').attr('disabled', 'disabled');
ob.removeAttr('disabled');
args[$(this).attr('name')] = $(this).val();
args[ob.attr('name')] = $(':selected', ob).text();
loader( $.param(args) );
})
$('select[name=foo]').change(function(){
var ob = $(this);
$('#uploader-wrapper').html(pre_load());
args[ob.attr('name')] = $(':selected', ob).text();
loader( $.param(args) );
});
});
with form:
<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
<p><label>Category: </label><input type="radio" name="for" class="radio" value="category" checked="checked" /><select name="foo"><option>...</option><?php global_data::show_breadcrum_list( 'option', " / " ); ?></select></p>
<p><label>Product: </label><input type="radio" name="for" class="radio" value="category" /><select disabled="disabled"><option name="foo">...</option><?php global_data::show_breadcrum_list( 'option', " / " ); ?></select></p>
<div id="uploader-wrapper">
<div class="fieldset flash" id="fsUploadProgress">
<span class="legend">Upload Queue</span>
</div>
<div id="divStatus">0 Files Uploaded</div>
<div>
<span id="spanButtonPlaceHolder"></span>
<input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
</div>
</div>
</form>

Related

Vuejs/Nuxtjs : How to create dynamic V-model names without using the v-for?

I am encountering a tricky issue in my Vuejs/Nuxtjs application. In the application, I am creating multiple Nodes dynamically. These Nodes have the Radio button for which I have assigned a v-model. However, when I change the value of one Vuejs v-model is affecting all other Node Values.
I am aware that this issue is happening because of the same v-model being used for all Nodes. I would like to assign a different V-model to my Radio button but I want to do it without using the v-for.
I have created the sample code in the CodeSandbox
Steps to reproduce:
Drag and drop the Identifiers into the canvas. Now the URN will be selected.
Now Drag and drop another Identifiers into the canvas. Now the first Identifiers Node: URN will disappear. I am unable to handle each Node value independently.
The problem is arising in the file #components/IdentifiersNode.vue and in the radio button.
Code sample based on the Kissu response :
<input
id="identifierTypeURN"
:data="identifierSyntax"
value="URN"
type="radio"
name="instanceIdentifierURN"
#input="instanceIdentifiersSyntaxChange('URN')"
>
<label for="identifierTypeURN">URN</label>
<input
id="identifierTypeWebURI"
:data="identifierSyntax"
value="WebURI"
type="radio"
name="instanceIdentifierWebURI"
#input="instanceIdentifiersSyntaxChange('WebURI')"
>
<label for="identifierTypeWebURI">WebURI</label>
Can someone please check and let me know what am I doing wrong here: https://codesandbox.io/s/cocky-matan-kvqnu?file=/nuxt.config.js
After some effort able to get it working. I was using the Radio button functionalities wrongly. I changed it to something like this and it worked fine:
<template>
<div ref="el">
<div class="header">Identifiers Node: {{ ID }}</div>
<div id="app" class="nodeContainer">
{{ "Value : " + identifierSyntax }}
Syntax:
<input
:id="`identifierTypeURN-${ID}`"
:data="identifierSyntax"
value="URN"
type="radio"
:name="`instanceIdentifier-${ID}`"
:checked="identifierSyntax === 'URN'"
#input="instanceIdentifiersSyntaxChange($event, 'URN')"
/>
<label :for="`identifierTypeURN-${ID}`">URN</label>
<input
:id="`identifierTypeWebURI-${ID}`"
:data="identifierSyntax"
value="WebURI"
type="radio"
:name="`instanceIdentifier-${ID}`"
:checked="identifierSyntax === 'WebURI'"
#input="instanceIdentifiersSyntaxChange($event, 'WebURI')"
/>
<label :for="`identifierTypeWebURI-${ID}`">WebURI</label>
</div>
</div>
</template>
<script>
export default {
data() {
return {
ID: "",
nodeId: "",
bizStep: "",
allNodeInfo: [],
identifierSyntax: "URN",
};
},
mounted() {
console.log("MOUNTED");
this.$nextTick(() => {
const id = this.$el.parentElement.parentElement.id;
const data = this.$df.getNodeFromId(id.slice(5));
this.ID = data.data.ID;
this.nodeId = data.data.nodeId;
this.allNodeInfo = JSON.parse(
JSON.stringify(
this.$store.state.modules.ConfigureIdentifiersInfoStore
.identifiersArray,
null,
4
)
);
this.identifierSyntax = this.allNodeInfo.find(
(node) => node.identifiersId === this.nodeId
).identifierSyntax;
});
},
methods: {
// On change of the IdentifierSyntax change, change the value in the respective node info
instanceIdentifiersSyntaxChange(event, syntaxValue) {
console.log("CHANGED : " + syntaxValue);
console.log(event.target.defaultValue);
this.identifierSyntax = syntaxValue;
// Change the value of the respective syntax within the Node information in IdentifiersNode array
this.$store.commit(
"modules/ConfigureIdentifiersInfoStore/identifiersSyntaxChange",
{ nodeId: this.ID, syntaxValue }
);
},
},
};
</script>
<style>
.header {
background: #494949;
margin-top: -15px;
margin-left: -15px;
margin-right: -15px;
padding: 10px 15px;
margin-bottom: 15px;
}
</style>

Upload an image after it's been cropped with vue-cropperjs - Base64 / Binary encode/decode issue

I have a form which allows users to upload an image, crop that image (utilising vue-cropperjs wrapper component) then upload the cropped image (not the original image).
I'm unable to provide the correct format for the file in order to upload it. The file has been converted (encoded) the base64 image string to display it on the page. I now need to covert (decode) it back into a file format to upload it (as a default image upload form input would do).
The view component can be found at: https://www.npmjs.com/package/vue-cropperjs
And the following coded is based on the code from this package's example, i've just added a upload method for this example:
<template>
<div id="app">
<h2 style="margin: 0;">Vue CropperJS</h2>
<form #submit.prevent>
<input v-model="imageName" type="text" />
<hr />
<input
type="file"
name="image"
accept="image/*"
style="font-size: 1.2em; padding: 10px 0;"
#change="setImage"
/>
<br />
<div style="width: 400px; height:300px; border: 1px solid gray; display: inline-block;">
<vue-cropper
ref="cropper"
:guides="true"
:view-mode="2"
drag-mode="crop"
:auto-crop-area="0.5"
:min-container-width="250"
:min-container-height="180"
:background="true"
:src="imgSrc"
alt="Source Image"
:img-style="{ 'width': '400px', 'height': '300px' }"
></vue-cropper>
</div>
<img
:src="cropImg"
style="width: 200px; height: 150px; border: 1px solid gray"
alt="Cropped Image"
/>
<br />
<br />
<div>Debug Output: {{ cropImg }}</div>
<br />
<br />
<button #click="cropImage" v-if="imgSrc != ''" style="margin-right: 40px;">Crop</button>
<br />
<br />
<button #click="submitForm" v-if="imgSrc != ''">Submit Form</button>
</form>
</div>
</template>
<script>
import VueCropper from "vue-cropperjs";
import "cropperjs/dist/cropper.css";
export default {
components: {
VueCropper
},
data() {
return {
imageName: "",
imgSrc: "",
cropImg: "",
};
},
methods: {
setImage(e) {
const file = e.target.files[0];
if (!file.type.includes("image/")) {
alert("Please select an image file");
return;
}
if (typeof FileReader === "function") {
const reader = new FileReader();
reader.onload = event => {
this.imgSrc = event.target.result;
// rebuild cropperjs with the updated source
this.$refs.cropper.replace(event.target.result);
};
reader.readAsDataURL(file);
} else {
alert("Sorry, FileReader API not supported");
}
},
cropImage() {
// get image data for post processing, e.g. upload or setting image src
this.cropImg = this.$refs.cropper.getCroppedCanvas().toDataURL();
},
submitForm() {
console.log("imageName: " + this.imageName);
console.log("cropImg: " + this.cropImg); //Output: data:image/png;base64,iVBORw0KGgoAAA (please note: i've truncated the value for this example)
//example of an file upload to firebase storage (this could apply for different solutions)
//I need to convert the base64 date back into a file in order to upload.
let e = this.cropImg;
if(e != null) {
const file = e;
console.log("upload file: " + file.name);
fb.storage
.ref("images/" + file.name)
.put(file)
.then(response => {
//etc
}
}
}
}
};
</script>
I have done some research into blobs, decoding etc - but have been unable to find a solid solution.
Ok i was able to solve this one myself - if anyone is interested i sent be base64 url to this method:
dataURLtoFile(dataurl, filename) {
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, {type:mime});
}
For more info see here

Column nowrap using datatables not working

Having a Datatable as below:
"Wifi Code" shows the wifi code value, and if the user has provided an email/phone, a respective button is added also to send email/Sms.
I'm trying to display "Wifi Code" in one line, with no wrap.
The table definition:
<table id="visitorsTable" class="display compact responsive nowrap" style="width: 100%">
The ColumnDefs:
columnDefs: [
{
targets: [10], // Wifi Code
className: "noWrapTd", // white-space: nowrap;
render: function(wifiCode, b, data, d) {
// wifi exists
if (wifiCode) {
var content = `<span class="mx-2">${wifiCode}</span>`;
if (data.Email && data.PhoneNumber) {
content +=
'<div>' +
'<button type="button" class="btnResendByMail mx-1">Email <i class="fas fa-envelope"></i></button>' +
'<button class="btnResendBySms">Sms <i class="fas fa-sms"></i></button>' +
'</div>';
return content;
} else {
if (data.Email) {
content +=
'<button class="btnResendByMail">Email <i class="fas fa-envelope"></i></button>';
}
if (data.PhoneNumber) {
content +=
'<button class="btnResendBySms">SMS <i class="fas fa-sms"></i></button>';
}
}
return content;
} else { // wifi does not exists
return '<button class="btnGenerate">Generate <i class="fas fa-wifi"></i></button>';
}
}
}
As you can already see, I have added the "nowrap" class to the table definition.
I've also tried to set a class "className: "noWrapTd", still not good.
Any other idea ?
Modified code:
columnDefs: [
{
targets: [10], // Wifi Code
className: "no-wrap",
width: "200px",
render: function(wifiCode, b, data, d) {
// wifi exists
if (wifiCode) {
var content = "<span class="mx-2">${wifiCode}</span>";
if (data.Email && data.PhoneNumber) {
content +=
'<div class="d-inline">' +
'<button type="button" class="btnResendByMail d-inline mx-1">Email <i class="fas fa-envelope"></i></button>' +
'<button class="btnResendBySms d-inline">Sms <i class="fas fa-sms"></i></button>' +
'</div>';
return content;
} else {
if (data.Email) {
content +=
'<button class="btnResendByMail d-inline">Email <i class="fas fa-envelope"></i></button>';
}
if (data.PhoneNumber) {
content +=
'<button class="btnResendBySms d-inline">Sms <i class="fas fa-sms"></i></button>';
}
}
return content;
} else { // wifi does not exists
return '<button class="btnGenerate d-inline">Generate <i class="fas fa-wifi"></i></button>';
}
}
}
]
First of all I removed the nowrap class from table definition:
<table id="visitorsTable" class="display compact responsive" style="width: 100%">
And the columnDefs:
className: "no-wrap", // Datatables no-wrap class
width: "200px", // Fixed width
Applied d-inline class for the buttons and the div containing the buttons

Watin. how to show invinsible class

HTML code:
<div class="col-sm-9">
<input name="NewCardOrAccountNumber" class="form-control ui-autocomplete-input" id="NewCardOrAccountNumber" type="text" value="" autocomplete="off">
<span class="ui-helper-hidden-accessible" role="status" aria-live="polite"></span>
</div>
<div class="unvisible" id="clientInfoNew">
<div class="form-group">
<label class="col-sm-3 control-label">FIRST NAME</label>
<div class="col-sm-9" id="FnameNew"></div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">LAST NAME</label>
<div class="col-sm-9" id="LnameNew"></div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">BIRTH DATE</label>
<div class="col-sm-9" id="BirthDateNew"></div>
</div>
Watin code:
[TestMethod]
[TestCategory("Rimi Change card page")]
public void Rimi_4444_Change_Card_and_Assert()
{
//Web Address
using (IE ie = new IE(this.Rimi))
{
//IE ie = new IE(RimiChangeCard);
ie.BringToFront();
ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Maximize);
ie.TextField(Find.ById("NewCardOrAccountNumber")).TypeText("9440385200600000020");
If I write card number from keyboard, the invisible class appear, and you can see FIRST NAME, LAST NAME and so on. But if I do this with watin, it does not appear, and you only see card number which you input. Its like hidden fields of information. I do not know how to make that I could see this fields when I input card number.
There would be a JavaScript function, which gets executed when you manually enter the data in the text field.Go through the Java Script functions on the same page which refer to that element using it's ID NewCardOrAccountNumber.
Refer to this link for sample application. Where msg_to is element, and has a KeyUp event associated. When that filed gets a , value, there is a div section inside which a `Subject' field is shown.
Similarly, after executing the TypeText, try to trigger related event mentioned in the Java Script event using Java script execution.
EDIT: I see that the javascript functions gets executed after bulr event is fired. This means the textbox field should loose the focus. Try the below options.
// 1. Try focusing out of control.
ie.TextField(Find.ById("NewCardOrAccountNumber")).TypeText("9440385200600000020");
ie.TextField(Find.ById("OldCardOrAccountNumber")).Click();
ie.WaitForComplete();
// 2. Try Using Send Keys method to tab out.
ie.TextField(Find.ById("NewCardOrAccountNumber")).TypeText("9440385200600000020");
System.Windows.Forms.SendKeys.SnedWait("{TAB}"); // Need to add System.Windows.Forms reference to the project.
I put image on the internet, so click on this link Image and you will see on first image how look page, second picture - what have to happen when you input card number (from keyboard), third - what happen when card namuber is input from watin (does not appear information about card).
HTML code:
<div class="ibox-content">
<br>
<div class="form-horizontal">
<div class="row">
<div class="col-md-5">
<div class="form-group">
<label class="col-sm-3 control-label">NEW CARD</label>
<input name="NewCardId" id="NewCardId" type="hidden" value="0" data-val-required="The NewCardId field is required." data-val-number="The field NewCardId must be a number." data-val="true">
<div class="col-sm-9"><span class="ui-helper-hidden-accessible" role="status" aria-live="polite"></span><input name="NewCardOrAccountNumber" class="form-control ui-autocomplete-input" id="NewCardOrAccountNumber" type="text" value="" autocomplete="off"></div>
</div>
<div class="unvisible" id="clientInfoNew">
<div class="form-group">
<label class="col-sm-3 control-label">FIRST NAME</label>
I maybe find what you looking for Sham, but I do not know how to use it :
<script type="text/javascript">
$(document).ready(function() {
var NewCardId = "#NewCardId";
var OldCardId = "#OldCardId";
var NewCardNumber = "#NewCardOrAccountNumber";
var OldCardNumber = "#OldCardOrAccountNumber";
$(NewCardNumber).autocomplete(
{
source: function(request, response) {
$.ajax({
url: '/LoyaltyWebApplication/Suggestion/GetCardSuggestions',
dataType: "json",
data: {
str: $(NewCardNumber).val()
},
success: function(data) {
response($.map(data, function(item) {
var label = "";
if (item.Fname != null) label += item.Fname;
if (item.Lname != null) label += " " + item.Lname;
if (label.trim() != '') label = " (" + label.trim() + ")";
return {
value: item.CardNumber,
label: item.CardNumber + label
}
}));
},
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
},
select: function(event, ui) {
getCardDetails($(NewCardNumber), $(NewCardId), 'newCardSegments', true);
$("#newCardSegments").hide();
$("#clientInfoNew").show();
},
minLength: 2
}).blur(function() {
getCardDetails($(NewCardNumber), $(NewCardId), 'newCardSegments', true);
});
$(OldCardNumber).autocomplete(
{
source: function(request, response) {
$.ajax({
url: '/LoyaltyWebApplication/Suggestion/GetCardSuggestions',
dataType: "json",
data: {
str: $(OldCardNumber).val()
},
success: function(data) {
response($.map(data, function(item) {
var label = "";
if (item.Fname != null) label += item.Fname;
if (item.Lname != null) label += " " + item.Lname;
if (label.trim() != '') label = " (" + label.trim() + ")";
return {
value: item.CardNumber,
label: item.CardNumber + label
}
}));
},
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
},
select: function(event, ui) {
getCardDetails($(OldCardNumber), $(OldCardId), 'oldCardSegments', false);
$("#oldCardSegments").hide();
},
minLength: 2
}).blur(function() {
getCardDetails($(OldCardNumber), $(OldCardId), 'oldCardSegments', false);
});
function getCardDetails(cardNumHolder, cardIdHolder, segmentTablePlace, isNew) {
$.getJSON('/LoyaltyWebApplication/LOV/SetId?lovType=ReplacementLOV&lovValue=' + cardNumHolder.val(), null,
function(data) {
$("#clientInfo" + ((isNew) ? "New" : "Old")).show();
if (cardNumHolder.val() == '') {
return;
}
var i;
for (i = 0; i < data.otherNames.length; i++) {
$("#" + data.otherValues[i] + (isNew ? "New" : "Old")).text(data.otherNames[i]);
}
cardIdHolder.val(data.Id);
$.getJSON('/LoyaltyWebApplication/Replacement/ClientSegmentsList?clientId=' + data.Id + "&no_cache=" + Math.random, function(data) {
$("#" + segmentTablePlace).find('tbody').empty();
if (data.length > 0) {
$.each(data, function(index) {
$("#" + segmentTablePlace).find('tbody').append("<tr><td>" + data[index].SegmentCode + "</td><td>" + data[index].SegmentName + "</td></tr>");
});
$("#" + segmentTablePlace).show();
}
});
});
}
$("#resetVal").click(function() {
$("#NewCardOrAccountNumber").attr("value", "");
$("#NewCardOrAccountNumber").val("");
$("#NewCardId").attr("value", "");
$("#NewCardId").val("");
$("#clientInfoNew").hide();
$("#OldCardOrAccountNumber").attr("value", "");
$("#OldCardOrAccountNumber").val("");
$("#OldCardId").attr("value", "");
$("#OldCardId").val("");
$("#clientInfoOld").hide();
return false;
});
});
</script>

Sometimes, dojo dgrid does not render the data correctly

I have a dgrid, and use JsonRest to get data from the server side. I pressed a button to filter the data.
Here is the html code:
<div data-dojo-type="dijit/TitlePane" title="<b>查询</b>">
<div class="row-fluid">
<div class="span12">
<div class="row-fluid">
<div class="span10 offset1">
<table>
<tr>
<td>批号:</td>
<td><input id="simple_store_dgrid_search_batch_no"
style="width: 120px; height: 20px"
data-dojo-type="dijit/form/TextBox" /></td>
</tr>
</table>
</div>
</div>
<div class="row-fluid">
<div class="span6 offset6">
<button type="button" id="simple_store_dgrid_clear_button">清除</button>
<button type="button" id="simple_store_dgrid_search_button">查询</button>
</div>
</div>
</div>
</div>
</div>
<div id="simple_store_dgrid_table_toolbar"></div>
<div id="simple_store_dgrid_table"></div>
js code:
require([ "dgrid/OnDemandGrid", "dgrid/Selection", "dgrid/Keyboard", "dojo/_base/declare",
"dojo/store/JsonRest", "dojo/store/Observable", "dgrid/extensions/Pagination",
"dijit/Toolbar", "dijit/form/Button", 'dojo/query', "dijit/registry", "dojo/domReady!" ],
function(Grid, Selection, Keyboard, declare, JsonRest, Observable, Pagination, Toolbar,
Button, query, registry) {
**var jsonRest = JsonRest({
target : "../rest/dGrid/",
idProperty : "batchId"
});
var store = Observable(jsonRest);**
var columns = [ {
label : '批号',
field : 'batchId',
sortable : true
}, {
label : '创建日期',
field : 'creationDate',
sortable : true
}, {
label : '创建人',
field : 'createdBy',
sortable : true
}, {
label : '描述',
field : 'description',
sortable : true
} ];
**var grid = new (declare([ Grid, Selection, Keyboard, Pagination ]))({
store : store,
getBeforePut : false,
columns : columns,
minRowsPerPage : 10,
pagingLinks : 1,
loadingMessage : '数据加载...',
selectionMode : "single",
noDataMessage : '没有查到数据'
}, "simple_store_dgrid_table");
grid.startup();**
var toolbar = new Toolbar({}, "simple_store_dgrid_table_toolbar");
var clear = new Button({
onClick : function() {
var batch_no = registry.byId("simple_store_dgrid_search_batch_no");
batch_no.set('value', '');
}
}, "simple_store_dgrid_clear_button");
var search = new Button({
onClick : function() {
**var batch_no = registry.byId("simple_store_dgrid_search_batch_no");
grid.set("query", {
batch_no : batch_no.get('value')
});**
}
}, "simple_store_dgrid_search_button");
});
I can always get data from the server side, but sometimes the data is not rendered.
Quita la paginacion:
Note: the Pagination extension should be mixed into List or Grid, NOT one of the OnDemand constructors, since those contain their own virtual scrolling logic. Internally, Pagination inherits from the same _StoreMixin module inherited by the OnDemand prototypes for common integration with dojo/store.
https://github.com/SitePen/dgrid/wiki/Pagination