Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By mustapah
#794262
I have a grid that needs to be sorted when the user clicks on "sort" button inside the dynaform. The grid has a hidden variable 'id', the sort will depend on this variable.
Code: Select all
sortButton.getControl().click(function() {
        var sortedArray = grid.getValue().sort((a, b) => {
           return  a[INDEX_ID] - b[INDEX_ID];
        });
        
        // this doesn't work, I know, but that what I need to do 
        grid.setValue(sortedArray);
});
User avatar
By amosbatto
#794880
PM has a PHP function to sort grids, but we don't have a JavaScript function. Here is an example showing how to sort a grid with JavaScript.

If you have a grid like this:
FormWithGridToSort.png
FormWithGridToSort.png (19.03 KiB) Viewed 7430 times
Then the following JavaScript can be used to sort the "clientList" grid by its second column ("Last Name"):
Code: Select all
// set to the column number to sort in the grid. 
// 0 is first column, 1 is the second column, etc.
var colNo = 1; 
//set to the ID of the grid:
var gridId = 'clientList'; 

//Function to sort case-insensitive strings. 
//If needing to sort numbers, then use
//parseFloat(a[colNo]) or parseInt(a[colNo])
function sortFunction(a, b) {
  var aUpper = a[colNo].toUpperCase();
  var bUpper = b[colNo].toUpperCase();
  
  if (aUpper === bUpper) {
    return 0;
  }
  else {
    return (aUpper < bUpper) ? -1 : 1;
  }
}

$("#form\\[sortButton\\]").click( function(){
  var oGrid = $("#"+gridId);
  var aGridVals = oGrid.getValue();
  aGridVals.sort(sortFunction);
  
  //delete all existing rows:
  var nRow = oGrid.getNumberRows();
  for (; nRow > 0; nRow--) {
    oGrid.deleteRow(nRow);
  }
  
  //add the sorted rows to the grid:
  for (var i = 0; i < aGridVals.length; i++) {
    var aRow = [];
    for (var ii = 0; ii < aGridVals[0].length; ii++) {
      aRow.push( {value: aGridVals[i][ii]} );
    }
    oGrid.addRow(aRow);
  }
});
When the user clicks on the "sortButton" button, the grid will be sorted in case-insensitive alphabetical order:
SortedGrid.png
SortedGrid.png (15.75 KiB) Viewed 7430 times
Here is a sample form for you to study:
(2.65 KiB) Downloaded 400 times
By azalea45
#830978
Dear All,
I have been trying to do a sort on a grid using the sort function that Amos created and having an interesting problem.
Before I get to the problem let me give some background to this Dynaform.
We are on Ubuntu 16.04 and Community 2.3
The Dynaform works as follows
1. The user selects a field (field1) from a dropdown box (the dropdown is populated by a database query).
2. Field1 then will populate dropdown box 2 (field 2). Field 2 is also populated by a database query with field1 as a variable. Field1 & field2 are cascading dropdowns.
3. The “primary key” is the value that is needed.
4. There is a button that will run a function that populates the first column in a grid.
5. The grid has 16 columns and some of the fields use a database to obtain a value for population and other fields need to be filled in by the user.
6. Column 16 (which gets is value from the database) needs to be the primary column for the sort.

Now for the problem
I have a button that will run the code below. When I click on the button all the row fill with the values from the last field. These are only on the fields that use database connections. The values filled in by the user remains unsorted.

I thought the problem was that it was using a shallow copy and when I tried a deep copy the problem still continued.
Based on the sort the function that I am using is as follows
Code: Select all
//set column no as the sort field
var colNo = 15;

//set to the ID of the grid:
var gridId = 'gridVar';

//Sort Function
function sortFunction (a,b){
	var aUpper = parseInt(a[colNo]);
  	var bUpper = parseInt(b[colNo]);   
  if (aUpper === bUpper) {
    return 0;
  }
  else {
    return (aUpper < bUpper) ? -1 : 1;
  }
}

$("#form\\[sortButton\\]").click( function(){
  var oGrid = $("#"+gridId);
  var aGridVals = oGrid.getValue();
  aGridVals.sort(sortFunction);
  //delete all existing rows:
  var nRow = oGrid.getNumberRows();
  for (; nRow > 0; nRow--) {
    oGrid.deleteRow(nRow);
  }
  //add the sorted rows to the grid:
  for (var i = 0; i < aGridVals.length; i++) {
    var aRow = [];
    for (var ii = 0; ii < aGridVals[0].length; ii++) {
      aRow.push( {value: aGridVals[i][ii]} );
    }
    oGrid.addRow(aRow);
  }
});
Does anyone have some suggestion on how to sort the grid and entire rows as I have run out of ideas. :? :?
Thanks
#831047
In today's globalized world, effective communication in English has become an essential skill for personal and professional success. Whether it's for academic pursuits, career advancements, or simply boosting one's confidence, the demand for impeccable spoken English skills is on the rise. As the cultural and educational hub of Maharashtra, Pune stands as a hotbed for those seeking to enhance their spoken English proficiency. Amidst the abundance of options available, selecting the right spoken English class can be a daunting task. This blog serves as your comprehensive guide, directing you to the best spoken English classes in Pune that will help you unlock your full linguistic potential.

Understanding the Importance of Spoken English:

Before delving into the specifics of the top spoken English classes in Pune , it's crucial to comprehend the significance of mastering spoken English. In a diverse and interconnected world, English serves as the lingua franca of business, education, and technology, facilitating communication across borders and cultures. A strong command of spoken English not only opens up a world of opportunities but also boosts confidence and fosters personal growth.

Unveiling the Best Spoken English Classes in Pune:

English by the Hour:
Known for its personalized approach and comprehensive curriculum, English by the Hour has emerged as a leading spoken English institute in Pune. With its team of experienced instructors and interactive learning modules, this institute caters to learners of all levels, from beginners to advanced speakers. The emphasis on practical application through conversational practice and real-life simulations sets English by the Hour apart from its competitors.

Fluent English Academy:
Dedicated to nurturing linguistic proficiency in a supportive and encouraging environment, Fluent English Academy is a popular choice for individuals seeking to refine their spoken English skills. Its well-structured courses, focusing on pronunciation, vocabulary expansion, and fluency enhancement, ensure that students develop a strong foundation in spoken English. The use of interactive learning tools and immersive activities makes the learning process engaging and effective.

SpeakWell Academy:
With a legacy of excellence in language training, SpeakWell Academy has established itself as a prominent institution for spoken English classes in Pune. Committed to fostering holistic development, SpeakWell Academy offers a range of courses tailored to meet the diverse learning needs of students. The incorporation of modern teaching methodologies, including audio-visual aids and group discussions, cultivates a dynamic and interactive learning experience.

Veta:
Renowned for its innovative teaching techniques and result-oriented approach, Veta remains a preferred choice for individuals aspiring to master spoken English. Through its comprehensive curriculum and specialized modules, Veta focuses on enhancing communication skills, public speaking, and overall confidence. The integration of technology-driven learning tools and one-on-one coaching sessions ensures that each student receives personalized attention and guidance.

Let's Talk:
Catering to the evolving demands of language learning, Let's Talk has earned accolades for its dynamic and engaging spoken English programs. By fostering a communicative approach and incorporating real-world scenarios, Let's Talk equips students with the necessary linguistic tools to navigate various social and professional contexts with ease. The incorporation of mock interviews and interactive group activities bolsters students' confidence and encourages active participation.

Choosing the Right Spoken English Class for You:

When selecting a spoken English class in Pune, consider factors such as the teaching methodology, the experience of the instructors, course structure, and the availability of personalized attention. Additionally, look for institutes that offer flexible timings and a conducive learning environment that encourages active participation and fosters a sense of community among learners.

Conclusion:

Mastering spoken English is not just about acquiring language skills; it is a transformative journey that opens up a world of opportunities and fosters personal growth. With the abundance of renowned spoken English classes in Pune, individuals can embark on this journey with confidence, guided by expert instructors and immersive learning experiences. Choose the right institute that resonates with your learning style and objectives, and embark on a fulfilling and enriching linguistic odyssey. Take the first step towards unlocking your full potential in spoken English today!

https://www.sevenmentor.com/spoken-engilsh-classes-in-pune.php

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]

Betvisa clone scripts are pre-built software solut[…]