I have problem with search function, I got the same results as before I made the search
I have problem with search function, I got the same results as before I made the search
alaaokby
Posts: 1Questions: 0Answers: 0
Hello,
I have a problem in search by column in server-side processing as that I got the same results as it is after searching here is my code,
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/search'],
function(Search) {
/**
* Function to be executed after page is initialized.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
*
* @since 2015.2
*/
function pageInit(scriptContext) {
try{
var url_string = window.location.href
var url = new URL(url_string);
var strRole = url.searchParams.get("role");
var arrColumns = new Array();
arrColumns.push({"data": "customerName","width": "40%" ,"searchable":true});
arrColumns.push({"data": "purchaseOrder", "width": "40%" ,"searchable":true});
arrColumns.push({"data": "orderNumber", "width": "40%","searchable":true });
arrColumns.push({"data": "invoiceNumber", "width": "40%","searchable":true });
arrColumns.push({"data": "orderDate", "width": "40%" ,"searchable":true});
arrColumns.push({"data": "shipDate", "width": "40%","searchable":true });
arrColumns.push({"data": "invoiceDate", "width": "40%" ,"searchable":true});
arrColumns.push({"data": "status", "width": "40%","searchable":true });
arrColumns.push({"data": "partNumber", "width": "40%" ,"searchable":true});
arrColumns.push({"data": "orderQty", "width": "40%","searchable":true });
arrColumns.push({"data": "shipQty", "width": "40%","searchable":true });
arrColumns.push({"data": "estShipDate", "width": "40%" ,"searchable":true});
arrColumns.push({"data": "trackingNumbers", "width": "40%" ,"searchable":true});
//
if(strRole == 'P'){
//arrColumns.push({"data": "fltUnitPrice"});
var colDefs = { className: 'text-center', targets: [ 3 , 4 ] };
}
else{
var colDefs = { className: 'text-center', targets: [ 2 , 3 ] };
}
//arrColumns.push({"data": "intBuildableNetQty"});
// arrColumns.push({"data": "strDiscontinued"});
//
//
$(document).ready(function() {
$.ajax({
url:"https://300382.app.netsuite.com/app/site/hosting/scriptlet.nl?script=843&deploy=1&role="+ strRole,
method:"POST",
success:function(data){
var DATA_TABLE = $('#data_table_items').DataTable({
"processing": true,
"serverSide":true,
"ajax":"https://300382.app.netsuite.com/app/site/hosting/scriptlet.nl?script=843&deploy=1&role="+ strRole,
//data:data,
"columns": arrColumns,
"bSort": false,
"paging": true,
//"sort": true,
"searching": true,
});
$('.search-sort').each(function() {
var title = $(this).text();
$(this).html('<input type="text" id="sInput" placeholder="Search ' + title + '" />');
});
DATA_TABLE.columns().every(function(){
var datatableColumn=this;
$(this.header()).find('input').on('keyup change', function() {
datatableColumn.search(this.value)
.draw()
});
})
}
})
});
// Setup - add a text input to each footer cell
//var DATA_TABLE = jQuery('#data_table_items').DataTable({
//"destroy":true,
//"filtering":false,
//"processing": true,
//"serverSide":true,
// "searching":false,
//"pageLength": 10,
// "responsive":true,
//"dataSrc":arrColumns,
//"ajax":{"url":"https://300382.app.netsuite.com/app/site/hosting/scriptlet.nl?script=843&deploy=1&role="+ strRole},
//"columnDefs": [
// colDefs
// ],
// initComplete: function() {
// var api = this.api();
// Apply the search
// api.columns(".search-sort").every(function() {
// var that = this;
// $('input', this.header()).on('keyup change', function() {
// if (that.search() !== this.value) {
// console.log(that.search())
// that
// .search(this.value)
// .draw();
// }
// });
//});
// }, // "columns": arrColumns,
//"bSort" : false,
// "data":function(d){
// return $.extend({},d,{
// "searchInput":$("#searchInput").val().toLowerCase(),
// })
// }} ,
// data: dataSet,
// "columns": [
// { "data": "strItemId" },
// { "data": "strSalesDesc" },
// { "data": "fltUnitPrice" },
// { "data": "intBuildableNetQty"},
// { "data": "strDiscontinued"},
// ],
// });
//console.log(DATA_TABLE)
//log.debug('role',strRole);
//jQuery('#searchInput').on( 'keyup', function () {
// var value = $(this).val();
//var regExSearch = '^\\s' + this.value +'\\s*$';
//DATA_TABLE.search(value).draw();
// DATA_TABLE.columns( '.select-filter' ).every( function () {
// var that = this;
// Create the select list and search operation
// var select = $('<select />')
// .appendTo(
// this.footer()
// )
// .on( 'change', function () {
// that
// .search( $(this).val() )
// .draw();
// } );
// Get the search data for the first column and add to the select list
// this
// .cache( 'search' )
// .sort()
// .unique()
// .each( function ( d ) {
// select.append( $('<option value="'+d+'">'+d+'</option>') );
// } );
//} );
// document.getElementById("divBody").innerHTML=divs;
//} );
// $(document).on("change",'#searchInput',function() {
// var value = $(this).val();
// DATA_TABLE.search('').columns('').draw();
//});
// $(document).ready(function() {
// DATA_TABLE.draw();
// $('#searchInput').bind("keyup change",function(){
// DATA_TABLE.draw();
//});
// });
// function searchByColumn(table) {
// var defaultSearch = 1 //Name
//$(document).on('change', '#select-column', function() {
// defaultSearch = this.value;
//});
//$(document).on('change', '#data_table_items_filter input', function() {
// table.search('').columns().search('').draw();
// table.column(defaultSearch).search(this.value).draw();
//});
//}
// var table = $('#data_table_items').DataTable();
// searchByColumn(table);
// } );
jQuery(".uir-outside-fields-table").css("width", "80%");
jQuery(".uir-outside-fields-table").css("margin-left", "auto");
jQuery(".uir-outside-fields-table").css("margin-right", "auto");
}catch(ex){
console.log('AF ERROR: ' + ex);
log.error('catch pageinit',ex);
}
}
return {
pageInit: pageInit,
};
});
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Replies
The search is performed by the server-side script, not the client, so that would be the place to look.
Colin